DATA STRUCTURE
QUEUE
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.#include<stdio.h>
#include<stdlib.h>
#define Max 5
int a[Max];
int rear=-1;
int front=-1;
void insert(int);
void delete();
void display();
void main()
{
int c,item;
do
{
printf("\nPress 1:Insert\nPress 2:Delete\nPress 3:Diplay\nPress 0:Exit\n");
scanf("%d",&c);
switch(c)
{
case 1:printf("Enter Element\n");
scanf("%d",&item);
insert(item);
break;
case 2:delete();
break;
case 3:display();
break;
case 0:exit(0);
}
}while(1);
}
void insert(int item)
{
if(rear==Max-1)
printf("Insertion not Possible\n");
else
{
rear++;
a[rear]=item;
}
}
void delete()
{
if(rear==front)
printf("Deletion not Possible\n");
else
{
front++;
printf("Deleted Element %d",a[front]);
}
}
void display()
{
int i;
printf("Queue :");
for(i=front+1;i<=rear;i++)
printf("%d ",a[i]);
}
,Thanks
Bikki Mahato