栈是一种只能从表的一端存取数据且遵循“先进后出”原则的线性存储结构
#include#include int push(int *a,int top,int elem) { top=top+1; a[top]=elem; return top; } //压栈 int pop(int *a,int top) { if(top==-1){printf("空栈");return -1;} printf("弹栈元素:%dn",a[top]); top--; return top; }//数据元素出栈 int main() { int a[100]; int top=-1; top=push(a,top,1); top=push(a,top,2); top=push(a,top,3); top=push(a,top,4); top=pop(a,top); top=pop(a,top); top=pop(a,top); top=pop(a,top); top=pop(a,top); return 0; }



