C++第十讲:堆栈

#include 
#include 
using namespace std;
void new_stack(stack  s)
{
	stack  t = s;
	while (!t.empty())
	{
		cout << '	' << t.top();
		t.pop();
	}
	cout << '
';
}
int main ()
{
	stack  newst;
	newst.push(5);
	newst.push(4);
	newst.push(3);
	newst.push(2);
	newst.push(1);

	cout << "最新的堆栈是 : ";
	new_stack(newst);   //相当于 print(list) 
	cout << "
 newst.size() : " << newst.size();
	cout << "
 newst.top() : " << newst.top();
	cout << "
 newst.pop() : ";
	newst.pop(); //删除最上面的一个元素 
	new_stack(newst);  //输出最新的堆栈 
	return 0;
}
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章