exp20_3.cpp

来自「高等教育出版社出版的C++程序设计同步实验范例 希望对用这本教材得同学有点帮助」· C++ 代码 · 共 25 行

CPP
25
字号
//stack适配器。首先看演示程序。

#include <iostream>
#include <stack>

int main()
{
	using namespace std;
	stack<int >s1,s2;									//	构造整数栈
	s1.push(10);										//	整数压栈
	s1.push(20);
	s1.push(30);
	stack<int >::size_type i;								//	用于存储栈的大小
	i = s1.size();
	cout<<"The Stack length is"<<i<<"."<<endl;
	i = s1.top();										//	取栈顶元素
	cout<<"The element at the top of the stack is"<<i<<"."<<endl;
	s1.pop();											//	出栈
	i = s1.size();
	cout<<"After a pop,the Stack length is"<<i<<"."<<endl;
	i = s1.top();
	cout<<"The element at the top of the stack is"<<i<<"."<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?