#include<conio.h> #include<stdio.h> void enqueue(); int dequeue(); int e[5],n=5,rear=-1,front=-1,i,ch='y',item; void main() { int c; clrscr(); while(ch=='y') { printf("\n\n1.Enqueue"); printf("\n\n2.Dequeue"); printf("\n\n3.Exit"); printf("\n\nEnter Choice:"); scanf("%d",&c); switch (c) { case 1: enqueue(); break; case 2: dequeue(); break; case 3: exit (0); } } getch(); } void enqueue() { if(rear==n) { printf("\n\nQueue is full"); } else { if(rear==front==-1) { front=0; } rear=rear+1; printf("\n Enter Your element::"); scanf("%d",&item); e[rear]=item; printf("%d",e[i]); printf("\n\n%d is inserted\n\n",item); } for(i=front;i<=rear;i++) { printf("\n\n%d",e[i]); } getch(); } int dequeue() { int i,n; if(front==-1) { printf("\n\nQueue is empty"); } else { int item; item=e[front]; printf("\n\n%d is pop\n\n",item); e[item]=NULL; front++; } for(i=front;i<=rear;i++) { printf("\n\n%d",e[i]); } return 0; }
WAP of Queue
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment