diff --git a/DS/C/Lab/Week4/circq.c b/DS/C/Lab/Week4/circq.c new file mode 100644 index 0000000..9c9eb83 --- /dev/null +++ b/DS/C/Lab/Week4/circq.c @@ -0,0 +1,63 @@ +#include + +#define MAX_SIZE 5 + +int queue[MAX_SIZE]; +int front = 0; +int rear = 0; + +void enqueue(int data) { + if ((rear + 1) % MAX_SIZE == front) { + printf("Queue is full\n"); + return; + } + queue[rear] = data; + rear = (rear + 1) % MAX_SIZE; +} + +int dequeue() { + if (front == rear) { + printf("Queue is empty\n"); + return -1; + } + int data = queue[front]; + front = (front + 1) % MAX_SIZE; + return data; +} + +void printQueue() { + if (front == rear) { + printf("Queue is empty\n"); + return; + } + int i = front; + while (i != rear) { + printf("%d ", queue[i]); + i = (i + 1) % MAX_SIZE; + } + printf("\n"); +} + +int main() { + int choice, data; + while (1) { + printf("1. Enqueue\n2. Dequeue\n3. Print Queue\n4. Exit\n"); + scanf("%d", &choice); + switch (choice) { + case 1: + printf("Enter data: "); + scanf("%d", &data); + enqueue(data); + break; + case 2: + data = dequeue(); + if (data != -1) printf("Dequeued: %d\n", data); + break; + case 3: + printQueue(); + break; + case 4: + return 0; + } + } +}