seqstack.htypedef struct stack{data data[size+1]; //Data Elements int top; //Top }SeqStack; Seqstack *seqstackinit () {seqstack *p;if (p= (seqstack *) (malloc) (sizeof (Seqstack))) // Application stack memory {p->top = 0; //set stack top is zero return p; //returns pointer to stack }return null;} Int seqstackisempty (seqstack *s) //determine if the stack is empty {return (s->top==0);} Void seqstackfree (seqstack *s) //freed Stack (s) free (s); } void Seqstackclera (seqstack *s) // empty stack {s->top = 0; } int seqstackfree ( seqstack *s) //judgment stack is full {return (s->top==size) ;} Int seqstackpush (seqstack *s, data data) // into stack operation {if ((s->top+1) >size) { printf ("Stack Overflow!\n"); return 0;} s->data[++s->top] = data; //stack element into the stack return 1; } data seqstackpop ( seqstack *s) The stack operation {if (s->top==0) {printf ("Stack is empty!"); Exit (0);} return (s->data[s->top--]);} Data seqstackpeek (seqstack *s) // read stack top data {if (s->top==0) {printf ("Stack is empty! "); exit (0);} return (S->data[s->top]); }
Data structure Stack Learning Note 1