#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int x;
struct node *next;
}*top;
void push();
void pop();
void peep();
int main()
{
int op;
do{
printf("\n...MENU...");
printf("\n1)Push node\n2)Pop node");
printf("\nenter 0 for EXIT");
printf("\nEnter your option :");
scanf("%d",&op);
switch(op)
{
case 1:
push();
break;
case 2:
pop();
break;
case 0:
printf("\n...BYE BYE!...");
break;
default :
printf("\nINVALID option");
break;
}
}while(op!=0);
return 0;
}
void push()
{
struct node *ptr;
ptr=(struct node *)malloc(sizeof(struct node));
if(ptr==NULL)
{
printf("\nstack overflow");
return;
}
printf("\npush element in node=");
scanf("%d",&ptr->x);
ptr->next=top;
top=ptr;
peep();
}
void pop()
{
struct node *ptr;
ptr=top;
if(top==NULL)
{
printf("\nstack is empty");
return;
}
printf("\n%d is poped",ptr->x);
top=top->next;
free(ptr);
peep();
}
void peep()
{
struct node *ptr;
ptr=top;
if(top==NULL)
{
printf("\nstack is empty");
return;
}
while(ptr!=NULL)
{
printf("\nelement=%d",ptr->x);
ptr=ptr->next;
}
}