0% found this document useful (0 votes)
22 views2 pages

2 Queue WITH Array

The document contains a C program that implements a queue using an array. It provides functionalities for enqueueing, dequeueing, and displaying the queue, along with a menu for user interaction. The program handles overflow and underflow conditions appropriately.
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)
22 views2 pages

2 Queue WITH Array

The document contains a C program that implements a queue using an array. It provides functionalities for enqueueing, dequeueing, and displaying the queue, along with a menu for user interaction. The program handles overflow and underflow conditions appropriately.
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

9/20/25, 11:09 AM queue_Using_array

1 #include <stdio.h>
2 #include<stdlib.h>
3 # define SIZE 100
4 void enqueue();
5 void dequeue();
6 void show();
7 int inp_arr[SIZE];
8 int Rear = - 1;
9 int Front = - 1;
10 int main()
11 {
12 int ch;
13 while (1)
14 {
15 printf("[Link] Operation\n");
16 printf("[Link] Operation\n");
17 printf("[Link] the Queue\n");
18 printf("[Link]\n");
19 printf("Enter your choice of operations : ");
20 scanf("%d", &ch);
21 switch (ch)
22 {
23 case 1:
24 enqueue();
25 break;
26 case 2:
27 dequeue();
28 break;
29 case 3:
30 show();
31 break;
32 case 4:
33 exit(0);
34 default:
35 printf("Incorrect choice \n");
36 }
37 }
38 return 0;
39 }
40
41 void enqueue() {
42 int insert_item;
43 if (Rear == SIZE - 1) {
44 printf("Overflow\n");
45 return;
46 } else {
47 printf("Element to be inserted in the Queue: ");
48 scanf("%d", &insert_item);
49
50 if (Front == -1) // First element
51 Front = 0;
52
53 Rear = Rear + 1;
54 inp_arr[Rear] = insert_item;
55 }

[Link] 1/2
9/20/25, 11:09 AM queue_Using_array
56 }
57
58 void dequeue()
59 {
60 if (Front == - 1 || Front > Rear)
61 {
62 printf("Underflow \n");
63 return ;
64 }
65 else
66 {
67 printf("Element deleted from the Queue: %d\n", inp_arr[Front]);
68 Front = Front + 1;
69 }
70 }
71
72 void show()
73 {
74
75 if (Front == - 1)
76 printf("Empty Queue \n");
77 else
78 {
79 printf("Queue: \n");
80 for (int i = Front; i <= Rear; i++)
81 printf("%d ", inp_arr[i]);
82 printf("\n");
83 }
84 }

[Link] 2/2

You might also like