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

Practical No 15

The document presents a C program for implementing simple queue operations using an array. It allows users to perform insertion, deletion, and display of queue elements, with a maximum size of 5. The program runs in an infinite loop until the user chooses to exit, handling various user inputs and conditions for queue operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Practical No 15

The document presents a C program for implementing simple queue operations using an array. It allows users to perform insertion, deletion, and display of queue elements, with a maximum size of 5. The program runs in an infinite loop until the user chooses to exit, handling various user inputs and conditions for queue operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PRACTICAL: 15

AIM: TO write a program to implement simple queue operations using an


array

CLASS: BCA 1st` year

NAME: Shreyash P. Bayskar

CODE:

#include <stdio.h>

#include <stdlib.h> // Required for exit()

#define n 5 // Size of the queue

int main() {

int queue[n], ch, front = 0, rear = 0, i, j = 1;

printf("Queue using Array");

printf("\n1. Insertion \n2. Deletion \n3. Display \n4. Exit");

while (1) { // Infinite loop until user chooses to exit

printf("\nEnter the Choice: ");

scanf("%d", &ch);

switch (ch) {

case 1: // Insertion

if (rear == n)

printf("\nQueue is Full");

else {

printf("\nEnter no %d: ", j++);

scanf("%d", &queue[rear++]);

break;

case 2: // Deletion
if (front == rear)

printf("\nQueue is Empty");

else

printf("\nDeleted Element is %d", queue[front++]);

break;

case 3: // Display

if (front == rear)

printf("\nQueue is Empty");

else {

printf("\nQueue Elements are: ");

for (i = front; i < rear; i++)

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

break;

case 4: // Exit

exit(0);

default:

printf("\nWrong Choice! Please see the options.");

return 0;

OUTPUT:

Queue using Array

1. Insertion

2. Deletion
3. Display

4. Exit

Enter the Choice: 1

Enter no 1: 10

Enter the Choice: 1

Enter no 2: 20

Enter the Choice: 1

Enter no 3: 30

Enter the Choice: 1

Enter no 4: 40

Enter the Choice: 1

Enter no 5: 50

Enter the Choice: 1

Queue is Full

Enter the Choice:

You might also like