I need help with these questions please :(
1. Write a function that takes as a parameter a queue of integers and returns a copy of the queue with all the elements stored in reverse order. Use a stack as a helper data structure.
queue<int> reverseQueue(queue<int> q) // pre: none // post: returns a queue with the elements stored in reverse order
For example, after creating a queue in the following way and calling the function:
queue<int> myQueue, rQueue; myQueue.push(1); myQueue.push(2); myQueue.push(3); rQueue = reverseQueue(myQueue);
then the resulting rQueue has 1 at the back, 2 in the middle, and 3 at the front.
2. Write a function that reverses a string by making use of a stack. Your function could push elements on the stack one by one, and then build up the result by popping them off the stack.
string reverseString(string s)
Any help would be appreciated.