Queue Data Structure
Queue Data Structure
Queue Data Structure
A Queue Data Structure is a fundamental concept in computer science used for storing and
managing data in a specific order. It follows the principle of “First in, First out” (FIFO), where
the first element added to the queue is the first one to be removed. Queues are commonly
used in various algorithms and applications for their simplicity and efficiency in managing
data flow.
#include <stdio.h>
void enqueue();
void dequeue();
void show();
int inp_arr[SIZE];
int Rear = - 1;
int Front = - 1;
main()
int ch;
while (1)
printf("1.Enqueue Operation\n");
printf("2.Dequeue Operation\n");
scanf("%d", &ch);
switch (ch)
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
show();
break;
case 4:
exit(0);
default:
void enqueue()
int insert_item;
if (Rear == SIZE - 1)
printf("Overflow \n");
else
if (Front == - 1)
Front = 0;
scanf("%d", &insert_item);
Rear = Rear + 1;
inp_arr[Rear] = insert_item;
void dequeue()
printf("Underflow \n");
return ;
else
Front = Front + 1;
void show()
if (Front == - 1)
else
printf("Queue: \n");
printf("\n");
Copy
Output:
1.Enqueue Operation
2.Dequeue Operation
4.Exit
1.Enqueue Operation
2.Dequeue Operation
4.Exit
1.Enqueue Operation
2.Dequeue Operation
4.Exit
Queue:
10 20
1.Enqueue Operation
2.Dequeue Operation
1.Enqueue Operation
2.Dequeue Operation
4.Exit
Queue:
20
Copy
2.
3. int queue[MAX_SIZE];
6.
8. if (rear == MAX_SIZE - 1) {
9. printf("Queue is full");
10. return;
11. }
13. front = 0;
14. }
15. rear++;
17. }
18.
19. int dequeue() {
23. }
25. front++;
27. }
28.
30. enqueue(10);
31. enqueue(20);
32. enqueue(30);
37. return 0;
38. }
Output:
10 20 30 Queue is empty-1
Explanation:
2. Then, we dequeue and print the front element of the queue, which is 10.
3. Next, we dequeue and print the front element of the queue again, which is 20.
4. Then, we dequeue and print the front element of the queue again, which is 30.
5. Finally, we make a dequeue from an empty queue that outputs "Queue is empty" and
returns -1.
Stack Queue
Add and delete elements from Add and delete elements from both sides. Adds elements to rear list
the top of a list Delete an element from the Front of a list
Recursion used for Data storage sequential processing for data process