Stack


Program

#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
class ListStack{
node *head;
public:
ListStack()
{
head=NULL;
}
void push(int info)
{
node *NewNode=new node;
NewNode->data=info;
NewNode->next=head;
head=NewNode;
}
int pop()
{
if(IsEmpty())
{
cout<<"Underflow occurs ";
return NULL;
}
int info;
node *cur=head;
info=head->data;
head=head->next;
delete cur;
            return info;
}
int IsEmpty()
{
if(head==NULL)
return 1;
return 0;
}
};
int main()
{
ListStack s;
s.push(20);
cout<<s.pop();
cout<<s.pop();
}

Comments

Popular posts from this blog

EXTRA INFORMATION ABOUT TECHNOLOGY