#include<iostream> #include<malloc.h> using namespace std; #define Elementtype unsigned int #define maxSize 100 #define error string::npos /*順序棧*/ typedef struct aaa *stack; struct aaa{ int top; Elementtype b[maxSize]; }; stack createStack(){ stack s=(stack )malloc(sizeof(struct aaa)); s->top=-1; return s; } Elementtype pop(stack s){ if(s->top<=-1||s->top+1>maxSize){return error;} else { return s->b[s->top--]; } } bool push(stack s,Elementtype a){ if(s->top+1>=maxSize||s->top<-1){return false;} else { s->b[++s->top]=a; return true; } } int main(){ stack s=createStack(); for(int i=1;i<=100;i++){ push(s,i); } cout<<pop(s)<<endl; cout<<pop(s)<<endl; return 0; } |
|