Add a new member function that copies the elements of this LStack in reverse order into another stack that is passed in as a parameter. The function prototype for the member function you are to implement is as follows. Do not assume otherStack is empty when this funciton is called, you should make sure it is empty before doing your work (Hint: clear() ).
/** reverse stack
* Copy the elements of this stack in reverse order onto another stack
*
* @param otherStack A reference to the other stack.
*
* @returns void Nothing returned explicitly, but the otherStack that is passed by
* reference will contain a copy of the elements of this stack in reverse order
* once this function finishes.
*/
template <class T>
void LStack<T>::reverseStack(LStack<T>& otherStack)
{
}
PLEASE DO IT IN C++
Code:
/** reverse stack
* Copy the elements of this stack in reverse order onto another
stack
*
* @param otherStack A reference to the other stack.
*
* @returns void Nothing returned explicitly, but the otherStack
that is passed by
* reference will contain a copy of the elements of this stack in
reverse order
* once this function finishes.
*/
template <class T>
void LStack<T>::reverseStack(LStack<T>&
otherStack)
{
//Clear the other stack
otherStack.clear();
//while this stack is not empty push the
contents
//of this stack to the new stack
//pop the contents of this stack.
while(!isEmpty())
{
otherStack.push(top());
pop();
}
}
int main() {
LStack<int> lStack;
LStack<int> newLStack;
lStack.push(1);
lStack.push(2);
lStack.push(3);
lStack.push(4);
lStack.push(5);
lStack.reverseStack(newLStack);
while (!newLStack.isEmpty())
{
cout << newLStack.top()
<< " ";
newLStack.pop();
}
return 0;
}
OUTPUT:

Add a new member function that copies the elements of this LStack in reverse order into...