Program 17
Program 17
struct Queue {
int items[MAX_SIZE];
int front;
int rear;
};
int main() {
struct Queue q;
q.front = -1;
q.rear = -1;
do {
printf("\nQueue Implementation using Array\n");
printf("1. Enqueue\n");
printf("2. Dequeue\n");
printf("3. Display\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("Enter the value to enqueue: ");
scanf("%d", &value);
enqueue(&q, value);
break;
case 2:
value = dequeue(&q);
if (value != -1)
printf("Dequeued element: %d\n", value);
break;
case 3:
display(&q);
break;
case 4:
printf("Exiting program.\n");
break;
Program 17 Page 1
Program 17
default:
printf("Invalid choice! Please enter a valid
option.\n");
}
} while(choice != 4);
return 0;
}
Program 17 Page 2
Program 17
Output
Queue Implementation using Array
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: 1
Enter the value to enqueue: 5
Enqueued: 5
Program 17 Page 3