lab_branch #1
@ -1,6 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MAX_SIZE 5
|
#define MAX_SIZE 4
|
||||||
|
|
||||||
int queue[MAX_SIZE];
|
int queue[MAX_SIZE];
|
||||||
int front = 0;
|
int front = 0;
|
||||||
@ -8,7 +8,7 @@ int rear = 0;
|
|||||||
|
|
||||||
void enqueue(int data) {
|
void enqueue(int data) {
|
||||||
if ((rear + 1) % MAX_SIZE == front) {
|
if ((rear + 1) % MAX_SIZE == front) {
|
||||||
printf("Queue is full\n");
|
printf("\n\nQueue is full\n\n\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queue[rear] = data;
|
queue[rear] = data;
|
||||||
@ -41,11 +41,12 @@ void printQueue() {
|
|||||||
int main() {
|
int main() {
|
||||||
int choice, data;
|
int choice, data;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
printf("Choose the Circular Queue option you would like to perform:\n");
|
||||||
printf("1. Enqueue\n2. Dequeue\n3. Print Queue\n4. Exit\n");
|
printf("1. Enqueue\n2. Dequeue\n3. Print Queue\n4. Exit\n");
|
||||||
scanf("%d", &choice);
|
scanf("%d", &choice);
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
printf("Enter data: ");
|
printf("Enter the value for the latest element: ");
|
||||||
scanf("%d", &data);
|
scanf("%d", &data);
|
||||||
enqueue(data);
|
enqueue(data);
|
||||||
break;
|
break;
|
||||||
@ -58,6 +59,9 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
return 0;
|
return 0;
|
||||||
|
default:
|
||||||
|
printf("Invalid choice.");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user