0% found this document useful (0 votes)
5 views4 pages

Experiment No

DSA file

Uploaded by

S. Royaljangir
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)
5 views4 pages

Experiment No

DSA file

Uploaded by

S. Royaljangir
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/ 4

EXPERIMENT NO = 6TH DSA

#include <stdio.h>

#include <stdlib.h>

#define MAX 3

char cq[MAX];

int front = -1, rear = -1;

void insert(char);

void delete();

void display();

int main() {

int choice;

char item;

while(1) {

printf("\n\n~~Main Menu~~");

printf("\n1. Insertion and Overflow Demo");

printf("\n2. Deletion and Underflow Demo");

printf("\n3. Display");

printf("\n4. Exit");

printf("\nEnter Your Choice: ");


scanf("%d", &choice);

switch(choice) {

case 1:

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

printf("\n~~Circular Queue Overflow~~");

} else {

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

scanf(" %c", &item); // space before %c to handle input correctly

insert(item);

break;

case 2:

if (front == -1) {

printf("\n~~Circular Queue Underflow~~");

} else {

delete();

break;

case 3:

display();

break;

case 4:

exit(0);
default:

printf("\nPlease enter a valid choice");

return 0;

void insert(char item) {

if (front == -1) {

front = 0;

rear = (rear + 1) % MAX;

cq[rear] = item;

printf("\nInserted element: %c", item);

void delete() {

char item = cq[front];

printf("\nDeleted element: %c", item);

if (front == rear) {

front = rear = -1; // Reset queue when the last element is removed

} else {

front = (front + 1) % MAX;


}

void display() {

if (front == -1) {

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

return;

printf("\nCircular Queue contents are: ");

int i = front;

while (i != rear) {

printf("%c ", cq[i]);

i = (i + 1) % MAX;

printf("%c ", cq[rear]);

printf("\nFront[%d] -> Rear[%d]", front, rear);

You might also like