Rajshahi University of Engineering & Technology: Lab Report
Rajshahi University of Engineering & Technology: Lab Report
Submitted By : Submitted To :
Series : 22 RUET
Output:
Queue is Empty!!
Enqueued element 1
Enqueued element 2
Enqueued element 3
Enqueued element 4
Enqueued element 5
1 2 3 4 5
Deleted : 1
2 3 4 5
Algorithm:
Enqueue:
• Increment rear by 1.
Dequeue:
Display:
Discussion:
The program handles boundary cases effectively and provides a foundation for exploring
advanced queue implementations like circular queues or dynamic queues.
Output:
Queue before reversing:
1234
4321
Algorithm:
1. Base Case
2. Recursive Steps
• Use the function dequeue(q) to remove and retrieve the element at the front.
2. Recursively call the reverse() function to process the remaining elements of the queue:
• reverse(q).
3. Enqueue the dequeued element back into the queue at the rear:
• Use the function enqueue(q, item) to add the element at the rear of the queue.
Discussion:
The implemented functions worked as intended, handling both normal and edge cases.
While the recursive approach is elegant and easy to implement, iterative methods may be
better suited for larger datasets due to stack limitations. The experiment serves as a strong
foundation for understanding queue operations and recursive algorithms.
54321
12345
Algorithm:
Using an Auxiliary Array (Efficient Approach)
• Dequeue all elements from the queue and store them in the array.
• Sort the array arr using a standard sorting algorithm (e.g., Quick Sort or Bubble Sort).
• Dequeue all elements from the queue and insert them into the priority queue.
Discussion:
The experiment successfully demonstrated sorting techniques for queues. Both approaches
were effective, with the choice of method depending on the specific use case. This
foundational experiment provides insights into how queues can be manipulated for
enhanced functionality in data structure applications.