0% found this document useful (0 votes)
8 views

Lab No 08

Data structure lab no 08

Uploaded by

2023msee7
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lab No 08

Data structure lab no 08

Uploaded by

2023msee7
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#define MAXSIZE 10
int queue_array[MAXSIZE];
int rear=-1;
int front=-1;
void insert(void);
void dequeue(void);
void display(void);
int main(void)
{
int option=1;
int choice;
printf("Queue operations\n");
while(option)
{
printf(".................\n");
printf("1.....>Enqueue\n");
printf("2......Dequeue\n");
printf("3.....>DISPLAY\n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:insert();
break;
case 2:dequeue();
break;
case 3:display();
break;
default:printf("You enter wrong choice\n");
break;
}
}
}
void insert()
{
int add_item;
if(rear==MAXSIZE-1)
printf("Queue is overflow\n");
else
{
if(front==-1)
front=0;
printf("Insert the element in the queue:\n");
scanf("%d",&add_item);
rear=rear+1;
queue_array[rear]=add_item;
}
}
void dequeue()
{
if(front==-1||front>rear)
printf("Queue is underflow\n");
else
{
printf("Element deleted from queue is:%d\n",queue_array[front]);
front=front+1;
}
}
display()
{
int i;
if(front==-1)
{
printf("Queue is empty\n");
}
else
{
printf("Queue is:\n");
for(i=front;i<=rear;i++)
printf("%d\n",queue_array[i]);
}
}

You might also like