[go: up one dir, main page]

0% found this document useful (0 votes)
24 views3 pages

Queue Implementation

This document contains a C program that implements a queue using an array. It provides functionalities to insert, delete, and display elements in the queue. The program runs in a loop until the user chooses to exit.

Uploaded by

Kruthika GC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Queue Implementation

This document contains a C program that implements a queue using an array. It provides functionalities to insert, delete, and display elements in the queue. The program runs in a loop until the user chooses to exit.

Uploaded by

Kruthika GC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

// QUEUE IMPLEMENTATION

#include<stdio.h>
#include<stdlib.h>
#define MAX 20

int Q[MAX],choice, front=-1, rear=-1;


void insert();
void delete();
void display();

int main()
{

printf("\n\t Implementation of Queue using Array");

while(1)
{
printf("\n\t 1.Insert \n\t 2. Delete\n\t 3.Display\n\t 4.Exit");
printf("\n EnterYour Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4: exit(0)
}
}
return 0;
}

void insert()
{
int val;
if (rear == MAX - 1)
{ printf("\nQueue is Full!!");
}
else {
if (front == -1)
front = 0;
rear++;
printf(" Enter Value you want to insert ");
scanf(" %d", &val);
Q[rear] = val;
printf("\n Value inserted in queue is %d ", val);
}
}
void delete()
{
if (front == -1)
printf("\nQueue is Empty!!");
else {
printf("\nDeleted element is : %d", Q[front]);
front++;
if (front > rear)
front = rear = -1;
}
}

void display()
{
int i;
if (rear == -1)
printf("\n The Queue is Empty!!!");
else {
printf("\nQueue elements are:\n");
for (i = front; i <= rear; i++)
printf("%d ", Q[i]);
}
printf("\n");
}

You might also like