class reversestack{
public:
int getlast()
{
int res = s.top();
s.pop();
if(s.empty())
return res;
else {
int last = getlast();
s.push(res);
return last;
}
}
void reverse()
{
if(s.empty())
return;
int i = getlast();
reverse();
s.push(i);
}
public:
stack<int> s;
};
用递归函数和栈逆序一个栈
最新推荐文章于 2019-10-27 19:53:40 发布