#include< stdio.h>
#include< conio.h>
#define NULL 0
void main()
{
struct node{
 int data;
 struct node *link;
};
typedef struct node node;
int val,ch;
node *front=NULL,*rear=NULL,*temp;
char c='y';
clrscr();
 while(c=='y')
 {
  printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit");
  printf("\n Enter your choice:");
  scanf("%d",&ch);
  switch(ch)
  {
   case 1:
    printf("\n Enter value:");
    scanf("%d",&val);
    temp=(node*)malloc(sizeof(node));
    temp->data=val;
    temp->link=NULL;
    if(front==NULL)
     front=rear=temp;
    else
     rear->link=temp;
    rear=temp;
    break;
   case 2:
    if(front==NULL)
    printf("\n Queue is empty.");
    else
    {
     temp=front;
     printf("\n Deleted element is:%d",temp->data);
     if(front==rear)
      front=rear=NULL;
     else
      front=front->link;
     free(temp);
    }
    break;
   case 3:
    if(front==NULL)
    printf("\n Queue is empty.");
    else
    {
     temp=front;
     printf("\n Queue content:");
     while(temp!=NULL)
     {
      printf("\t %d",temp->data);
      temp=temp->link;
     }
    }
    break;
   case 4:
    exit(0);
  }
 }
getch();
}
OUTPUT
1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Queue is empty. 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:1 Enter value:11 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:1 Enter value:22 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:1 Enter value:33 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:3 Queue content: 11 22 33 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Deleted element is:11 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Deleted element is:22 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Deleted element is:33 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Queue is empty.
Comments
Post a Comment