7-3-1.cpp
来自「学习c++的ppt」· C++ 代码 · 共 35 行
CPP
35 行
#include <iostream.h>
#define STACKSIZE 10
class Stack {
private:
long buffer[STACKSIZE];
long *sp;
public:
Stack() { sp = buffer; }
~Stack() { };
void push(long data) {
if(sp >= buffer+STACKSIZE)
cerr << "Stack overflow !" << endl;
else {
*sp ++ = data;
cout << data << " is pushed !" << endl;
}
}
long pop() {
if(sp <= buffer) {
cerr << "Stack is Empty!" << endl;
return 0;
}
else return *--sp;
}
};
main()
{ Stack a;
a.push(351); a.push(7075461); a.push(3225);
cout << endl;
cout << a.pop() << " is poped !" << endl;
cout << a.pop() << " is poped !" << endl;
cout << a.pop() << " is poped !" << endl;
cout << a.pop() << " is poped !" << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?