#include
#include
using namespace std;
void Reverse(stack s1, stack s2)
{
for (int j=5; j>0; j--)
{
s1.push(j);
}
int stacksize = s1.size();
int sortsize = 0;
while (stacksize - sortsize > 0)
{
int temp = s1.top();
s1.pop();
while (s1.size() - sortsize > 0)
{
s2.push(s1.top());
s1.pop();
}
s1.push(temp);
sortsize++;
while (!s2.empty())
{
s1.push(s2.top());
s2.pop();
}
}
while (!s1.empty())
{
cout << s1.top() << endl;
s1.pop();
}
}
int main(void)
{
stack s1;
stack s2;
Reverse(s1, s2);
return 0;
}
阅读(535) | 评论(0) | 转发(0) |