用数组奥现栈 (6)栈的应用 例程序的嵌套,中断的嵌套 proc Ao proc Bo proc call BOiK call COK 口■■■口口口■口■口口■ 程序C 程序B 程序A
用数组实现栈 (6)栈的应用 例 程序的嵌套,中断的嵌套 proc A( ) ...... call B( ); ...... proc B( ) ...... ...... call C( ) ...... proc C( ) ...... ...... ...... 程序A 程序B 程序C
用数组奥现 (6)栈的应用 程序的嵌套,中断的嵌套 ■"■ proc A( proc b( proc call BO; call(()月 程序C 程序B 程序A
用数组实现栈 (6)栈的应用 程序的嵌套,中断的嵌套 proc A( ) ...... call B( ); ...... proc B( ) ...... ...... call C( ) ...... proc C( ) ...... ...... ...... 程序A 程序B 程序C 程序A 程序B 程序C
栈的链弌存储结构及运箕 用链表实现栈 入栈 出栈a1 a2 圆■■■■ an Httpd 栈顶在表头 (1)定义 typedef struct Stack_ type( node type* top; int length stack type;
栈的链式存储结构及运算 ◼ 用链表实现栈 a1 a2 …… an head 栈顶在 表头 (1)定义 typedef struct lstack_type{ node_type * top; int length; }lstack_type; 入栈 出栈 top
栈的链式存储结构及运犷 (2)压入push void push(stack, new_ node) new node->next= stack->top; stack→>top= new node; stack→| nath++ stack->top a ■■■ (3)弹出pop node type* pop(stack node type*out, new out= stack→>top; stack→top= stack→top>next; stack->length - return out
栈的链式存储结构及运算 (2)压入push void push(stack, new_node){ new_node->next = stack->top; stack->top = new_node; stack->length ++; } (3)弹出pop node_type * pop(stack){ node_type* out; out = stack->top; stack->top = stack->top->next; stack->length --; return out; } a1 new stack->top ……
4)的链式存储结抱及运基 stack top =s N, int empty(stack) if(stack top = NULL) return YES. else return No (5)置栈空 能否简单的使用 stacktop=NULL? 如果栈中还有链点,必须逐个将链点占用的空间释放 void clean(stack node type* temp; whil(! empty(stack)1、逐个将链点弹出 temp=pop( stack)2、释放链点空间 free(temp);]
栈的链式存储结构及运算 (4)栈空判断 stack.top == NULL; (5)置栈空 能否简单的使用 stack.top = NULL ? 如果栈中还有链点,必须逐个将链点占用的空间释放 void clean(stack){ node_type * temp; while( ! empty(stack)){ temp = pop(stack); free(temp); } } int empty(stack){ if(stack.top == NULL) return YES; else return NO; } 1、逐个将链点弹出 2、释放链点空间