Stacks and queues

Stack (Stack) is an important linear structure, a LIFO (Last in first out, LIFO) data structure. It requires only footer delete and insert operations.

Top of the stack (Top) of the end of the table is called a stack, the stack corresponding header called bottom (bottom).

typedef struct
{
    ElemType * Base ; // stack bottom 
    elemType * Top;
     int STACKSIZE; // maximum capacity 
} sqStack;
#define STACK_INIT_SIZE  100
initStack(sqStack *s)
{
    s->base = (ElemType *)malloc(STACK__INIT_SIZE*sizeof(ElemType));
    if( !s->base)
       exit(0);
    S -> Top = S-> Base ; // beginning, is the bottom of the stack the stack 
    S-> = the stackSize STACK_INIT_SIZE;
}

 

Pop operations
Pop(sqStack *s, ElemType *e)
{
    if( s->top == s->base )
         return;
    *e = *--(s->top)
}

Guess you like

Origin www.cnblogs.com/wy9264/p/12080717.html
Recommended