#include<stdio.h> #include<stdlib.h> typedef struct { int* data; int maxsize; int top; } Seqstack; void InitStack(Seqstack* s,int maxsz) { s->maxsize=maxsz; s->data=(int*)malloc(sizeof(int)*maxsz); s->top=-1; } void Push(Seqstack* s,int x) { s->top++; s->data[s->top]=x; } int Pop(Seqstack* s) { int tmp = s->data[s->top]; s->top--; return tmp; } int main() { Seqstack ss; InitStack(&ss,10); Push(&ss,1); Push(&ss,2); Push(&ss,3); printf("%d ",Pop(&ss)); printf("%d ",Pop(&ss)); printf("%d ",Pop(&ss)); return 0; }
简单做了下,就不写注释了。