//Dynamic Implimentation Of Stack
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int info;
struct node *next;
}NODE;
NODE *top;
void initstack()
{
top=NULL;
}
int isempty()
{
return(top==NULL);
}
void push()
{
int num;
NODE* nn=(NODE*)malloc(sizeof(NODE));
nn->info=num;
nn->next=NULL;
nn->next=top;
top=nn;
}
int pop()
{
int num;
NODE * temp = top;
num = top -> info;
top = top -> next;
free (temp);
return num;
}
void main()
{
int choice, n;
initstack();
do
{
printf("\n1.PUSH \n2.POP \n3.EXIT\n");
printf("Enter Your Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:/*PUSH*/
printf("\n ENTER THE TO BE PUSHED:");
scanf("%d",&n);
push(n);
break;
case 2:/*POP*/
if(isempty())
printf("\n >>STACK IS EMPTY<<");
else
printf("\n POPPED ELEMENT:%d",pop());
break;
default:
printf("\n>>ENTER THE RIGHT CHOICE<<\n");
}
}while(choice!=3);
}