The implementation characteristics of the stack filo (advanced post-out)
Assuming that the stack has a space of 8
top = = 0 cannot be out of the stack, has reached the bottom of the stack
top = = 8 can not be in the stack, has reached the top of the stack
Top always points to a position to be inserted
Push operation, 1. Write data, 2.top++ 3. If the stack is not full
Pop operation, 1.top--, 2. Eject Data 3. If the stack is not empty
#include <stdio.h>//need a continuous spacetypedef struct_stack{Charmem[1024x768];intTop;} Stack; Stack s;//Determine if the stack is fullintIsfull (Stack *ps) {returnPs->top = =1024x768;//ps-> = = 1024 is true, return 1, that is full when the return True}//Determine if the stack is emptyintIsEmpty (Stack *ps) {returnPs->top = =0;//ps->top = = 0; The time is empty stack}//In-stack operationvoidPush (Stack *ps,CharCH) {ps->mem[(Ps->top) + +] = ch;//Let Ps.mem's pointer ps.top++ and then assign a value}//Play OperationsCharPop (Stack *ps) {returnps->mem[--(Ps->top)];//First pointer to Ps.mem--, and returns}intMain () {Stack s = {{0},0}; for(Charch = ' a '; Ch <= ' z '; ch++) {if(!isfull (&s)) push (&S,CH); } while(!isempty (&s)) {Putchar (pop (&s));//EjectPuts" "); }}/*ZyxWvuTsRQPoNmLkJIhgFeDCba*/
C + + (implementation of data structure stacks)