/* program........
wap to implement
stack using dynamic implementation */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct
node
{
int data;
struct node *next;
}node;
void main()
{
int op,x;
node *rear,*front,*p;
front=NULL;
rear=NULL;
clrscr();
do
{
printf("\nmain menu:");
printf("\n1)insert\n2)delete\n3)display\n4)exit");
printf("\nenter your
choice");
scanf("%d",&op);
switch(op)
{
case 1: printf("\nenter
element");
if(rear==NULL)
{
rear=front=(node*)malloc(sizeof(node));
scanf("%d",&rear->data);
rear->next=NULL;
}
else
{
p=(node*)malloc(sizeof(node));
scanf("%d",&p->data);
p->next=NULL;
rear->next=p;
rear=p;
}
break;
case 2: p=front;
x=p->data;
front=p->next;
free(p);
printf("\ndeleted
element is:%d",x);
break;
case 3: if(rear==NULL)
printf("\nqueue is
empty");
else
{
p=front;
printf("\nqueue is:");
while(p!=NULL)
{
printf("<-%d",p->data);
p=p->next;
}
}
break;
}
}while(op!=4);
getch();
}
No comments:
Post a Comment