#define StackSize 6
typedef struct {
int data[StackSize];
int top;
}SeqStack;
#include"stdio.h"
#include"stdlib.h"
#include"S.h"
void InitStack(SeqStack *p){
p->top =-1;
}
int EmptyStack(SeqStack *p){
if(p->top ==-1)
return 1;
else
return 0;
}
int FullStack(SeqStack *p){看是否为满栈
if(p->top ==StackSize-1)
return 1;
else
return 0;
}
void EnterStack(SeqStack *p,int x){进栈
p->top ++;
p->data[p->top ] =x;
}
int LeaveStack(SeqStack *p){出栈
int x;
x=p->data [p->top ];
p->top --;
return x;
}
main(){
SeqStack *p;
int arr[]={1,2,3,4,5,6};
int i,x;
p=(SeqStack*)malloc(sizeof(SeqStack));
InitStack(p);
for(i=0;i<StackSize;i++){
EnterStack(p,arr[i]);
}
for(i=0;i<StackSize;i++){
x=LeaveStack(p);
printf("%d ",x);
}
system("pause");
}