QUEUE1

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

//Linear Queue using array

//call by value
#include<stdio.h>
#define size 10
int LQ[size];
int isEmpty(int,int);
int isFull(int);
int Insert(int);
int Delete(int,int);
void Display(int,int);
void main()
{
int front,rear,choice;
clrscr();
do{
printf("\nMenu\n1. Insert:\n2. Delete:\n3. Display:\n4. Exit\nEnter your choice:
");
scanf("%d",&choice);
switch(choice)
{
case 1: Insert(rear);break;
case 2: Delete(front,rear);break;
case 3: Display(front,rear);break;
case 4: exit(0);
}
}while(choice<=4);
getch();
}
int isEmpty(int front,int rear)
{
return(front==rear);
}
int isFull(int rear)
{
return(rear==size-1);
}
int Insert(int rear)
{
if(isFull(rear))
printf("\nLinear Queue is full.");
else
{
printf("\nEnter element: ");
scanf("%d",&LQ[++rear]);
}
return(rear);
}
int Delete(int front,int rear)
{
if(isEmpty(front,rear))
printf("\nLinear Queue is empty.");
else
{
printf("\nDeleted element = %d",LQ[++front]);
}
return(front);
}
void Display(int front,int rear)
{
int i;
if(isEmpty(front,rear))
printf("\nLinear Queue is empty.");
else
{
for(i=front+1;i<=rear;i++)
printf("%d\t",LQ[i]);
}
}

You might also like