#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int queue[10],front=1,rear=1,ch,val,i;
clrscr();
do{
printf("i.insert 2.delete 3.display 4.exit");
scanf("%d",& ch);
if(ch == 1)
{
printf("Enter the value");
scanf("%d", &val);
if(front == [rear+1]+6)
printf("queue is full");
else
if(front == 1 && rear == 1)
{
front =0;
rear =0;
queue[rear] = val;
}
else if(rear<5)
{
rear rear+1;
queue[rear] = val;
}
else if(rear == 5 && front != 0)
{
rear = 0;
queue[rear] =val;
}
if(ch == 2)
{
if(front<=rear)
printf("%d",queue[front++]);
else if(front < 5)
printf("%d",queue[front++]);
else
if(front == 5 && rear != 0)
front = 0;
else
printf("queue is empty");
}
if(ch == 3)
{
if(front <= rear)
{
for(i=front;i<=rear;i++)
printf("%d",queue[i]);
for(i=front;i<5;i++)
printf("%d",queue[i]);
}
}
if(ch == 4)
{
exit(0);
}
}while(1);
getch();
}
No comments:
Post a Comment