之顺序( (3)顺序线的基本操作(判的 判断栈是否空 int stackempty(sQsTACK S return s top==-1;
栈之顺序栈(cont’d) (3) 顺序栈的基本操作(判断): int stackempty(SQSTACK s) { return s.top == -1; } • 判断栈是否空
之顺序c( (4)顺序找的基本操作入线: 入栈 int push( SQSTACK“s, elemtype e) f(s→)top= MAXSIZE-1) return0;体栈满,入栈失败* S→>top++; s→>lem|s→>topl=e; return 1
栈之顺序栈(cont’d) (4) 顺序栈的基本操作(入栈): int push(SQSTACK *s, elemtype e) { if(s→top==MAXSIZE-1) return 0; /*栈满,入栈失败*/ s→top++; s→elem[s→top]=e; return 1; } • 入栈
之顺序c( 5)顺序线的基本操出线: 出栈 int pop(sQsTACK *s, elemtype if(s→>top=1) return0;*栈空,出栈失败* e=s→> elems→)topl; →)top-; eturn 1
栈之顺序栈(cont’d) (5) 顺序栈的基本操作(出栈): int pop(SQSTACK *s, elemtype *e) { if(s→top==-1) return 0; /*栈空,出栈失败*/ *e=s→elem[s→top]; s→top--; return 1; } • 出栈
之顺序c( (6)顺序线的基本操作获取 获取栈顶值 int gettop(SQSTACK S, elemtype *e) if(s-top==-Dreturn 0; e=s→> elem s→>topl;
栈之顺序栈(cont’d) (6) 顺序栈的基本操作(获取): int gettop(SQSTACK s,elemtype *e) { if(s→top==-1)return 0; *e=s→elem[s→top]; } • 获取栈顶值
传之链式线 3、链式:用链表实现的线 (1)链式线的数据类型定义(与链表相同): typedef struct node elemtype data struct node *next: JNODE, NODEPTR, * LKSTACK; #define len sizeof(Node
栈之链式栈 3、链式栈:用链表实现的栈 (1) 链式栈的数据类型定义(与链表相同): typedef struct node { elemtype data; struct node *next; }NODE ,*NODEPTR, *LKSTACK; #define LEN sizeof(NODE)