//stack 的基本操作
#include <iostream>
using namespace std;
const int maxn = 3;
typedef struct Stack
{
//NumType num;
int num;
}Stack;
int top = 0;//当前元素位置的上一个元素
Stack stack[maxn];
bool is_empty();
bool is_full();
int pop();
void push(const int &key);
int get_top();
bool make_empty();
int main()
{
int tmp;
cout << get_top() << " " << pop() << endl;// 这句话和下面存在同样的错误
cout << "Input a set of integers:(-1 is over)" << endl;
while(cin >> tmp)
{
if(tmp == -1) break;
push(tmp);
}
tmp = get_top();
cout << tmp << endl;
tmp = pop();
cout << tmp << endl;
//cout << pop() << " " << get_top() << endl;
//cout << get_top() << " " << pop() << endl;// 这样输出会发生非常奇妙的事情的
return 0;
}
// if stack is empty return true
bool is_empty()
{
return (top == 0);
}
// if stack is full return true
bool is_full()
{
return (top == maxn);
}
// pop the top number if not empty
int pop()
{
if(is_empty())
{
cout << "The Stack is empty,Cannot pop..." << endl;
return -1;
}
else
{
top --;
return stack[top].num;
}
}
// push one number,if not full
void push(const int &key)
{
if(is_full())
{
cout << "The Stack is full,Cannot push..." << endl;
return;
}
else
{
stack[top].num = key;
top ++;
}
}
// get the top number,not pop
int get_top()
{
if(is_empty())
{
cout << "The Stack is empty,Cannot get top..." << endl;
return -1;
}
else
{
return stack[top-1].num;
}
}
bool make_empty()
{
top = 0;
}//stack 的基本操作
#include <iostream>
using namespa