#include<stdio.h>
#include<conio.h>
#define boundary 5
struct queue
{
int item[boundary];
int front,rear;
};
struct queue q;
void insertion();
void display();
void delet();
int main ()
{
int ch=0;
q.front=0;
q.rear=-1;
clrscr();
while(ch!=4)
{
printf("\n1. Insertion\n2. Deletion\n3. Display\n4. Exit\n\n");
scanf("%d",&ch);
switch(ch)
{
case 1: insertion();
break;
case 2: delet();
break;
case 3: display();
break;
default : printf("\nPlease enter the right choise!\n");
}
}
}
void insertion()
{
int e,i,j;
if(q.rear+1==boundary)
printf("No space!\n");
else
{
printf("Enter the element: ");
scanf("%d",&e);
q.rear++;
q.item[q.rear]=e;
//-------------------------------------------------------Aesending
for(i=q.front+1;i<=q.rear;i++)
{
for(j=(q.front);j<q.rear;j++)
{
if(q.item[i]<q.item[j])
{
q.item[i]=((q.item[i]+q.item[j])-(q.item[j]=q.item[i]));
}
}
}
}
}
void display()
{
int i;
if(q.rear<q.front)
printf("No data in queue!\n");
else
{
printf("\nThe elements are: ");
for(i=q.front;i<=q.rear;i++)
printf("%d ",q.item[i]);
printf("\n");
if(boundary==i)
printf("Queue is full!\n");
}
}
void delet()
{
if(q.rear+1==q.front)
printf("No data in queue!\n");
else
q.front++;
}
Related posts: