There are two interesting linear tables: Stack and queue ).
Stack is defined in this way. Its elements follow the principle of first-in-first-out, and there is only one portal, called the top stack. The action to go into the stack is push, and the action to go out of the stack is pop.
It is easy to implement because it is based on a linear table and has such a simple and clear definition.
// 2013.3.6 // Lincoln // stack sequence storage structure # include
# define OK 1 # define error-1 # define true 1 # define false 0 # define maxlength 20 struct stack {int data [maxlength]; int top ;}; int push (struct stack * stack, int element) {If (Stack-> Top = MAXLENGTH-1) Return Error; int Index = ++ stack-> top; // top is auto-incrementing first and then assigned to index // int Index = stack-> top ++; // top is assigned to index first and then auto-incrementing. Note This. Stack-> data [Index] = element; Return OK;} int POP (struct stack * stack) {If (Stack-> Top =-1) return error; stack-> top --; Return OK;} void print (struct stack * stack) {If (Stack-> Top =-1) return; int size = stack-> top + 1; for (INT I = 0; I
data [% d] = % d \ n", I, stack-> data [I]) ;}} int main () {struct stack ={{ 0}, 0}; push (& stack, 30); push (& stack, 12); print (& stack ); pop (& stack); print (& stack); Return 0 ;}