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

Untitled Document 7

Uploaded by

pruthvi07u
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 views2 pages

Untitled Document 7

Uploaded by

pruthvi07u
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/ 2

#include <stdio.

h>
int queue[5];
int f = -1, r = -1;

// Function to insert an element in the queue


void insert() {
int item;
if (r == 4 {
printf("Queue is full\n");
} else {
printf("Enter the item to insert: ");
scanf("%d", &item);
r++;
queue[r = item;
printf("%d inserted\n", item);
}
}

// Function to delete an element from the queue


void delet() {
if (r == -1 || f > r) {
printf("Queue is empty\n");
} else
{
int item = queue[front];
printf("%d deleted\n", item);
f++;
}
}
}

void show() {
if (r == -1||f>r) {
printf("Queue is empty\n");
} else {
printf("Queue elements: ");
for ( i = front; i <= rear; i++) {
printf("%d ", queue[i]);
}
printf("\n");
}
}

int main() {
int ch;
do {
printf("\n1. Insert\n");
printf("2. Delete\n");
printf("3. Show\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &ch);

switch (ch) {
case 1: insert(); break;
case 2: delet(); break;
case 3: show(); break;
case 4: printf("Exiting...\n"); break;
default: printf("Wrong choice! Please try again.\n");
}
} while (ch != 4);

return 0;
}

You might also like