目录
1.功能
2.功能模块
3.全局代码
1.功能
1)push,入栈
2)pop,弹栈
3)top,取栈顶元素
4)empty,判空
2.功能模块
1)定义结构体
typedef struct stack
{
int top;
int* data;
int length;
}Stack;
2)push,入栈
//push, 将元素推入栈
status push_stack(Stack& S,int tmp)
{
if(!S.data)
{
return ERROR;
}
if(S.length == MAXSIZE)
{
cout << "栈区元素已满" << endl;
}
S.top++;
S.data[S.top] = tmp;
S.length++;
return OK;
}
3)pop,弹栈
//pop, 将元素弹出栈
status pop_stack(Stack& S)
{
if(!S.data)
{
return ERROR;
}
if(S.length == 0)
{
cout << "栈区为空" << endl;
}
S.top--;
S.length--;
return OK;
}
4)top,取栈顶元素
//top, 取栈顶的元素
int top_stack(Stack S)
{
if(!S.data)
{
return ERROR;
}
if(S.length == 0)
{
cout << "栈区为空" << endl;
}
return S.data[S.top];
}
5)empty,判空
//empty,判空
bool empty(Stack S)
{
if(!S.data)
{
exit(OVER);
}
if(S.length != 0)
{
return true;
}
return false;
}



