Write a program to sort a stack in ascending order. You should not make any assump-
tions about how the stack is implemented. The following are the only functions that
should be used to write this program: push | pop | peek | isEmpty.
#include <iostream>
using namespace std;
Stack sort(Stack s)
{
Stack r;
while (!s.isEmpty())
{
int tmp = s.pop();
while (!r.isEmpty() && r.peek() > tmp)
{
s.push(r.pop());
}
r.push(tmp);
}
}
辅助栈r中一定是倒序的,