Monday 21 October 2013

Program In C For Circular Queue Implementation Using Array

#include<stdio.h>
#include<conio.h>
void main()
{ int queue[10],SIZE=10,i,ch,c,item,front=-1,rear=-1,c2;
clrscr();
again:
c=1;
printf("QUEUE MENU: ");
printf("\n1.Insertion(Press 1)\n2.Deletion(Press 2)\n3.Display Queue(Press 3):\n");
scanf("%d",&ch);
if(ch==1)
{ while(c==1)
{ if((front==0 && rear==SIZE-1) || (front==rear+1))
printf("\n\nQueue is full.");
else
{
printf("\n\nEnter ITEM: ");
scanf("%d", &item);
if(rear == -1)
{
rear = 0;
front = 0;
}
else if(rear == SIZE-1)
rear = 0;
else
rear++;
queue[rear] = item;
printf("\n\nItem inserted: %d\n", item);
}
printf("\nQueue After Insertion Is: ");
for(i=front;i<=rear;i++)
{ printf("%d\t",queue[i]); }
printf("\nWant To Insert More ?? Press 1 for Yes and 2 For No: \n");
scanf("%d",&c);
}}
else if(ch==2)
{ while(c==1)
{ if(front == -1)
printf("\n\nQueue is empty.\n");
else
{
item = queue[front];
if(front == rear)
{
front = -1;
rear = -1;
}
else if(front == SIZE-1)
front = 0;
else
front++;
printf("\n\nITEM deleted: %d", item);
}
printf("\nQueue After Deletion Is: ");
for(i=front;i<=rear;i++)
{ printf("%d\t",queue[i]); }
printf("\nWant To Delete More ?? Press 1 for Yes and 2 For No: \n");
scanf("%d",&c); }}
else if(ch==3)
{ if(front==-1||front==rear+1)
printf("Queue Is Empty !!! ");
else
{ printf("Queue Is: ");
for(i=front;i<=rear;i++)
{ printf("%d\t",queue[i]); }
}}
else
printf("Invalid Choice !!!!!! ");
printf("\n1.Back To Main Menu(Press 1)\n2.Exit(Press Any Key):\n");
scanf("%d",&c2);
if(c2==1)
goto again;
}

No comments:

Post a Comment