📄 stack.cpp
字号:
//堆栈类模板的测试程序
#include "iostream.h"
#include"tstack1.h"
main()
{
Stack<float>floatStack(9);
float f=1.10;
cout<<"将float类元素压入floatStack上"<<endl;
while(floatStack.push(f)){//入栈成功是函数回返回1
cout<<f<<' ';
f+=1.10;
}
cout<<"栈已经满了,不能再压入元素"<<endl<<endl<<"从floatStack中取出元素"<<endl;
while(floatStack.pop(f))//出栈成功是函数回返回1
cout<<f<<' ';
cout<<"栈是空的,不能取出元素"<<endl<<endl;
cout<<"**********************************************************"<<endl;
/***************************************************************************************/
Stack<int>intStack;
int i=1;
cout<<endl<<"将int类元素压入intStack上"<<endl;
while(intStack.push(i)){//入栈成功是函数回返回1
cout<<i<<' ';
i++;
}
cout<<"栈已经满了,不能再压入元素"<<endl<<endl<<"从intstack中取出元素"<<endl;
while(intStack.pop(i))//入栈成功是函数回返回1
cout<<i<<' ';
cout<<"栈是空的,不能取出元素"<<endl<<endl;
cout<<"**********************************************************"<<endl;
/*************************************************************************************/
Stack<char>charStack(9);
char a='a';
cout<<endl<<"将元素压入charStack上"<<endl;
while(charStack.push(a)){//入栈成功是函数回返回1
cout<<a<<' ';
a++;
}
cout<<"栈已满,不能再压入元素"<<endl<<endl<<"从charStack中取出元素"<<endl;
while(charStack.pop(a))//出栈成功是函数回返回1
cout<<a<<' ';
cout<<"栈是空的,不能取出元素"<<endl<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -