#include <iostream> #include <stack> using namespace std; int getAndRemoveLastElement(stack<int>& stack) { int value = stack.top(); stack.pop(); if (stack.empty()) { return value; } else { int last = getAndRemoveLastElement(stack); stack.push(value); return last; } } void reverse(stack<int>& stack) { if (stack.empty()){ return; } int value = getAndRemoveLastElement(stack); reverse(stack); stack.push(value); } int main() { stack<int> test; test.push(1); test.push(2); test.push(3); reverse(test); while (!test.empty()) { cout << test.top() << endl; test.pop(); } return 0; }