main.cpp

来自「数据结构及C++相关的一些小程序」· C++ 代码 · 共 20 行

CPP
20
字号
#include"iostream.h"
#include<cstdlib>
#include"stack.h"
void main()//主函数用来进行测试
{
	char ch;
	stack<char> s;//建立字符型堆栈s
	s.push('A');//将字符A压入堆栈
    s.push('B');//将字符B压入堆栈
	s.push('C');//将字符C压入堆栈
	cout<<"Now the value of top is "<<s.top<<" after push three elements into the stack."<<endl;
    s.pop();//弹出栈顶的元素
	ch=s.topandpop();//弹出栈顶的元素并且返回其值给ch
	cout<<"Now the value of top is "<<s.top<<" after two pops."<<endl;
    cout<<"Now the value of ch is:"<<endl<<ch<<endl;
	cout<<"Now the top element of stack is:"<<endl<<s.getTop()<<endl;
	s.pop();//继续弹出栈顶元素
	s.pop();//此时程序会报错,显示堆栈已空
}

⌨️ 快捷键说明

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