DSU-PR-8

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practical-8

#include<stdio.h>
#include<conio.h>
#define MAX 8
int queue[MAX];
int front, rear = -1, val;
void enqueue() {
if (rear == MAX - 1) {
printf("Queue is full");
}
else if (rear == - 1 && front == -1) {
front++;
rear++;
printf("Enter the element: ");
scanf("%d", &val);
queue[rear] = val;
}
else {
rear++;
printf("Enter element: ");
scanf("%d", &val);
queue[rear] = val;
}
}
void dequeue() {
if (front == - 1) {
printf("Queue is empty");
}
else if (front == rear) {
printf("Deleted element is: %d", queue[front]);
front--;
rear--;
}
else {
printf("Deleted element is: %d", queue[front]);
front++;
}
}
void display() {
int i;
if (front == - 1) {
printf("Queue is empty");
}
else {
for (i = front; i < rear; i++) {
printf("%d ", queue[i]);
}
}
}

void main() {
int option;
clrscr();
do {
printf("\n****MAIN MENU****");
printf("\n1. Enqueue");
printf("\n2. Dequeue");
printf("\n3. Display");
printf("\n4. Exit");
printf("\nEnter your option: ");
scanf("%d", &option);
switch(option) {
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
}
}while(option != 4);
getch();
}
Output:
****MAIN MENU****
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your option: 1
Enter element: 23

****MAIN MENU****
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your option: 3
23
****MAIN MENU****
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your option: 2
Deleted element is: 23
****MAIN MENU****
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your option: 4

You might also like