0% found this document useful (0 votes)
2 views5 pages

Experiment 5

The document contains a C program that implements a circular queue with operations for enqueueing, dequeueing, and displaying elements. It includes a menu-driven interface allowing users to insert, delete, and view elements in the queue. The program demonstrates successful execution with sample inputs and outputs for various operations.

Uploaded by

Sharayu Kulkarni
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)
2 views5 pages

Experiment 5

The document contains a C program that implements a circular queue with operations for enqueueing, dequeueing, and displaying elements. It includes a menu-driven interface allowing users to insert, delete, and view elements in the queue. The program demonstrates successful execution with sample inputs and outputs for various operations.

Uploaded by

Sharayu Kulkarni
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/ 5

Roll no: 18

Name: Sharayu Sandeep Kulkarni

#include<stdio.h>

#define MAX 6

int queue[MAX];

int front=-1;

int rear=-1;

void enqueue(int element) {

if(front==-1 && rear==-1) {

front = 0;

rear=0;

queue[rear]=element;

else if ((rear+1)%MAX==front) {

printf("Queue if overflow...\n");

else{

rear=(rear+1)%MAX;

queue[rear]=element;

void dequeue() {

if (front==-1 && rear==-1) {


printf("Queue if underflow...\n");

else if (front==rear) {

printf("The dequeued element is %d\n", queue [front]);

front=-1;

rear=-1;

else{

printf("The dequeued element is %d\n", queue[front]);

front=(front+1)%MAX;

void display() {

int i= front;

if (front==-1 && rear==-1) {

printf("Queue is empty...\n");

else{

printf("Elements in the queue are:\n");

while(i!=rear) {

printf("%d\t", queue[i]);

i=(i=1) % MAX;

printf("%d\n", queue[rear]);

}
}

int main(){

int choice=1, x;

printf("Press 1: Insert an element\n");

printf("Press 2: Delete an element\n");

printf("Press 3: Display an elements\n");

printf("Press 4: Exit\n");

while(choice!=0) {

printf("\nEnter your choice:");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("Enter the element which is to be inserted:");

scanf("%d", &x);

enqueue(x);

break;

case 2:

dequeue();

break;

case 3:

display();

break;

case 4:

printf("Exiting...\n");

break;
default:

printf("Wrong choice... Enter the correct choice\n");

return 0;

Output

Press 1: Insert an element

Press 2: Delete an element

Press 3: Display an elements

Press4: Exit

Enter your choice:1

Enter the element which is to be inserted:20

Enter your choice:1

Enter the element which is to be inserted:40

Enter your choice:1

Enter the element which is to be inserted:80

Enter your choice:1

Elements in queue are:

20 40 80
Enter your choice:2

The dequeued element is:20

Enter your choice:3

Enter the element which is to be inserted:20

Elements in queue are:

40 80

Enter your choice:4

Exiting…

===Code Execution Successful===

You might also like