derivedarraystack.cpp
来自「《数据结构、算法与应用》从C++语言应用角度列举了要点」· C++ 代码 · 共 45 行
CPP
45 行
// test stack derived from arrayList
#include <iostream>
#include "derivedArrayStack.h"
#include "myExceptions.h"
using namespace std;
int main(void)
{
derivedArrayStack<int> s;
// add a few elements
s.push(1);
s.push(2);
s.push(3);
s.push(4);
cout << "Stack should be 1234, bottom to top" << endl;
// test empty and size
if (s.empty())
cout << "The stack is empty" << endl;
else
cout << "The stack is not empty" << endl;
cout << "The stack size is " << s.size() << endl;
while (!s.empty())
{
cout << "Stack top is " << s.top() << endl;
s.pop();
cout << "Popped top element" << endl;
}
try {s.pop();}
catch (stackEmpty message)
{
cout << "Last pop failed " << endl;
message.outputMessage();
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?