using namespace std;
struct node
{
int data;
struct node *next;
};
class stack_list
{
struct node *start;
public:
stack_list()
{
start=NULL;
}
void push(int item);
int pop();
void display();
};
void stack_list::push(int item)
{
struct node *temp,*p;
p=(struct node*)malloc(sizeof(node));
p->data=item;
p->next=start;
start=p;
}
void stack_list::display()
{
struct node *temp;
int item;
temp=start;
while(temp!=NULL)
{
cout<<temp->data<<"->";
temp=temp->next;
}
}
int stack_list::pop()
{
struct node *temp;
int item;
if(start!=NULL)
{
temp=start;
start=start->next;
item=temp->data;
free(temp);
}
else
{
cout<<"list is empty";
}
return(item);
}
int main()
{
stack_list stl;
int a;
stl.push(100);
stl.push(200);
stl.push(300);
stl.push(400);
stl.push(500);
stl.display();
a=stl.pop();
cout<<"deleted data is:"<<a;
return 0;
}
Comments