Untitled
Anonymous
plain_text
08/27/2026 6:53 AM
4.2 KB
0
Indexable
#include <stdio.h>
int main() {
int q[100], front = 0, rear = -1;
int choice, x;
while (1) {
printf("\n1 to enqueue\n");
printf("2 to dequeue\n");
printf("3 to calculate size\n");
printf("4 to exit\n");
scanf("%d", &choice);
if (choice == 1) {
scanf("%d", &x);
q[++rear] = x;
printf("Queue - ");
for (int i = front; i <= rear; i++)
printf("%d ", q[i]);
printf("\n");
}
else if (choice == 2) {
if (front > rear)
printf("Queue is empty\n");
else
front++;
}
else if (choice == 3) {
printf("Size = %d\n", rear - front + 1);
}
else if (choice == 4) {
break;
}
}
return 0;
}
}
}
}
}
}
}Editor is loading...
Leave a Comment