?? stack_cd.cpp
字號:
#include <iostream.h>
#define ARR_SIZE 100
class stack
{
int stck[ARR_SIZE];
int stack_top;
public:
stack();
~stack();
void push(int i);
int pop();
};
stack::stack(void)
{
stack_top = 0;
cout << "Stack Initialized" << endl;
}
stack::~stack(void)
{
cout << "Stack Destroyed" << endl;
}
void stack::push(int i)
{
if (stack_top==ARR_SIZE)
{
cout << "Stack is full." << endl;
return;
}
stck[stack_top] = i;
stack_top++;
}
int stack::pop(void)
{
if (stack_top==0)
{
cout << "Stack underflow." << endl;
return 0;
}
stack_top--;
return stck[stack_top];
}
void main(void)
{
stack obj1, obj2;
obj1.push(1);
obj2.push(2);
obj1.push(3);
obj2.push(4);
cout << obj1.pop() << endl;
cout << obj1.pop() << endl;
cout << obj2.pop() << endl;
cout << obj2.pop() << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -