Stack isAdvanced and laterData structure.
Stack operations include:Stack entry, stack exit, initialize stack, clear stack, traverse stack.
The C code is as follows:
# Include <stdio. h> # define maxsize 20 typedef int elemtype; typedef struct stack {elemtype data [maxsize]; int top ;}stack; // initialize stack void initstack (stack * s) {S-> Top =-1 ;}// void pushstackvalue (stack * s) {printf ("input the value of stack Member: \ n (0-Exit) \ n "); int value; printf (" Please input the 1st value of Stack: \ n "); scanf (" % d ", & value ); s-> data [++ S-> top] = value; while (value) {S-> top ++; printf ("Please input the % DST value of Stack: \ n ", S-> top + 1); scanf (" % d ", & value); s-> data [S-> top] = value ;}} // output stack void popstackvalue (stack * s) {If (S-> top> = 0) {printf ("the stack % DST value pop out: % d \ n ", s-> top + 1, S-> data [-- s-> top]);} else {printf ("the stack is empty \ n ");}} // determine the empty stack void isempty (stack * s) {If (S-> Top =-1) {printf ("the stack is empty. \ n ");} else {printf (" the stack is not empty. \ n ") ;}/// clear the stack void clearstack (stack * s) {S-> Top =-1;} // traverse the stack void scanstack (stack * s) {int I; int Len = s-> top-1; int stackarray [Len]; for (I = Len; I> 0; I --) {stackarray [I] = s-> data [I --];} printf ("the all stack member (from top to bottom) is: \ n "); while (LEN> = 0) {printf ("% d", S-> data [Len --]);} printf ("\ n");} void main () {stack s; initstack (& S); pushstackvalue (& S); scanstack (& S); isempty (& S); popstackvalue (& S ); popstackvalue (& S );}
The running result is as follows:
Reprinted by Liu