# C++ Queue: Exercises, Practice, Solution

## C++ Queue [27 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

From Wikipedia,
In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. By convention, the end of the sequence at which elements are added is called the back, tail, or rear of the queue, and the end at which elements are removed is called the head or front of the queue, analogously to the words used when people line up to wait for goods or services.

1. Write a C++ program to implement a queue using an array with enqueue and dequeue operations. Find the top element of the stack and check if the stack is empty, full or not.

Click me to see the solution

2. Write a C++ program to reverse the elements of a queue.

Click me to see the solution

3. Write a C++ program to sort the elements of a queue.

Click me to see the solution

4. Write a C++ program to find the sum of all elements of a queue.

Click me to see the solution

5. Write a C++ program to find the average of all elements of a queue.

Click me to see the solution

6. Write a C++ program to find the median of all elements of a queue.

Click me to see the solution

7. Write a C++ program to find the mode of all elements of a queue.

Click me to see the solution

8. Write a C++ program to find the mean, variance and standard deviation of all elements of a queue.

Click me to see the solution

9. Write a C++ program to find the maximum element of a queue.

Click me to see the solution

10. Write a C++ program to find the minimum element of a queue.

Click me to see the solution

11. Write a C++ program to find the second highest element of a queue.

Click me to see the solution

12. Write a C++ program to find the second lowest element of a queue.

Click me to see the solution

13. Write a C++ program to remove a given element from a queue.

Click me to see the solution

14. Write a C++ program to remove all the elements from a queue.

Click me to see the solution

15. Write a C++ program to remove all even elements from a queue.

Click me to see the solution

16. Write a C++ program to remove all odd elements from a queue.

Click me to see the solution

17. Write a C++ program to remove all duplicate elements from a queue.

Click me to see the solution

18. Write a C++ program to remove all elements greater than a number from a queue.

Click me to see the solution

19. Write a C++ program to concatenate two queues.

Click me to see the solution

20. Write a C++ program to copy one queue to another.

Click me to see the solution

21. Write a C++ program to find the top and bottom elements of a queue.

Click me to see the solution

22. Write a C++ program to get the Nth element from the bottom of a queue.

Click me to see the solution

23. Write a C++ program to get the Nth element from the top of a queue.

Click me to see the solution

24. Write a C++ program to find the position of an element in a queue.

Click me to see the solution

25. Write a C++ program to check if two queues are equal.

Click me to see the solution

26. Write a C++ program to find the intersection of two queues.

Click me to see the solution

27. Write a C++ program to find the union of two queues.

Click me to see the solution

CPP Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

﻿