Lakhankumawat / LearnCPP

Learn Cpp from Beginner to Advanced ✅ Practice 🎯 Code 💻 Repeat 🔁 One step solution for c++ beginners and cp enthusiasts.
https://lakhankumawat.github.io/LearnCPP/
MIT License
598 stars 484 forks source link

Reversing a stack and a queue using recursion #1531

Closed 072arushi closed 2 years ago

072arushi commented 2 years ago

Given a stack, the task is to sort it such that the top of the stack has the greatest element.

Example 1: Input: Stack: 3 2 1 Output: 3 2 1

Example 2: Input: Stack: 11 2 32 3 41 Output: 41 32 11 3 2

Given a Queue Q containing N elements. The task is to reverse the Queue. Your task is to complete the function rev(), which reverses the N elements of the queue.

Example 1: Input: 6 4 3 1 10 2 6 Output: 6 2 10 1 3 4 Explanation: After reversing the given elements of the queue, the resultant the queue will be 6 2 10 1 3 4.

Example 2: Input: 4 4 3 2 1 Output: 1 2 3 4 Explanation: After reversing the given elements of the queue, the resultant the queue will be 1 2 3 4.

github-actions[bot] commented 2 years ago

Hello @072arushi, thanks for creating your first issue at LearnCPP, hope you followed the guidelines.