#include
#include
typedef struct student node;
void Push();
void Pop();
void Display();
struct student
{
int rollno;
node *next;
}*top,*newrec;
void main()
{
clrscr();
int choice=0,n,i;
while(choice!=4)
{
printf("\n==============Menu===============");
printf("\n| 1. Insert Item into the Stack |");
printf("\n| 2. Delete from the Stack |");
printf("\n| 3. Display the Stack Items |");
printf("\n| 4. Exit the Application |");
printf("\n=================================");
printf("\n Enter the Choice :->");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n HOW MANY ITEMS YOU WANT TO PUSH INTO THE STACK :->");
scanf("%d",&n);
for(i=0;i
scanf("%d",&newrec->rollno);
if(top==NULL)
newrec->next=NULL;
else
newrec->next=top;
top=newrec;
}
void Pop()
{
node *ptr;
if(top==NULL)
printf("\n Stack is underflowing !!!");
else
{
ptr=top;
top=ptr->next; //Imagine linked list from opposite direction and top as head.
free(ptr);
}
}
void Display()
{
node *ptr;
int srno=0;
ptr=top;
if(ptr==NULL)
{
printf("\n Stack is Empty");
return;
}
printf("\n------------------------");
printf("\nSr. No. Record Value ");
while(ptr!=NULL)
{
srno++;
printf("\n %d %d ",srno,ptr->rollno);
ptr=ptr->next;
}
printf("\n------------------------");
}
No comments:
Post a Comment