linear queue using array
linear queue using array
In this representation we take one variable array type to contain elements of queue,other side we use to variable as name FRONT and REAR which represent index value of array.
A queue is called underflow if both FRONT and REAR must be assigned with -1. It is called overflow if rare is equivalent to(size-1)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
int queue[50],size,front=-1,rear=-1;
void insertion();//function prototype
void deletion();
void show();
main()
{
int choice;
printf("enter the sixe of queue-");
scanf("%d",&size);
printf("enter choice===");
do
{
system("cls");
printf("press 1 for insert value in queue\npress 2 for delete value\npress 3 for show all element\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
insertion(); break;
case 2:
deletion(); break;
case 3:
show(); break;
default:
printf("Invalid choice!");
}
}
while(choice>=1||choice<=3);
system("pause");
}
void insertion()
{
int iteam;
if(rear==size-1)
printf("queue is overflow");
else{
printf("enter the vlaue of queue=");
scanf("%d",&iteam);
if(rear==-1)
front=rear=0;
else
rear=rear+1;
queue[rear]=iteam;
}
}
void deletion()
{
if(front==-1)
printf("queue is underflow");
else
{
printf("deleted element=%d",queue[front]);
if(front==rear)
front=rear=-1;
else
front=front+1;
}
}
void show()
{
int i;
if( front==-1)
printf("queue is underflow");
else
{
printf("All element of queue=\n");
for(i=front;i<=rear;i++)
{
printf("%d\t",queue[i]);
}
system("pause");
}
}
Great anku
ReplyDeleteThank u
DeleteSupperb @nk
ReplyDeleteThank u dost
Delete