标签:style blog color io os ar sp div c
#include<iostream> #include<cstring> #include<cstdlib> #define maxsize 1000 using namespace std; //顺序结构 typedef struct { int data[maxsize]; int top; }SqStack; //初始化栈 void initStack(SqStack *&s) { s = new SqStack; s->top = -1;//空栈 } void Clearstack(SqStack *&s) { delete s; } //求栈的长度 int StackLength(SqStack *s) { return (s->top+1); } //判断栈是否为空 int StackEmpty(SqStack *s) { return (s->top == -1); } //进栈 int push(SqStack *&s,int e) { if (s->top == maxsize - 1)//栈满的情况,栈上溢出 return 0; s->top++; s->data[s->top] = e;//将e插进栈顶 return 1; } //出栈 int pop(SqStack *&s,int e) { if (s->top == -1)//空栈情况,栈下溢出 return 0; e= s->data[s->top]; s->top--; return 1; }
标签:style blog color io os ar sp div c
原文地址:http://www.cnblogs.com/tong1487/p/4011759.html