计算机组成原理(唐朔飞)答案
计算机组成原理(唐朔飞) 第二版 答案,
# include<stdio.h> # define STACK_INIT_SIZE 100 # define STACKINCREMENT 10 typedef int SElemType; struct SqStack{ SElemType * base; SElemType * top; int stacksize; int Length; }; struct SqStack S; SElemType * e; void InitStack () { S.base=(SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType)); if(!S.base) printf("OVER\n"); else { S.top=S.base; S.stacksize=STACK_INIT_SIZE; S.Length=0; printf("OK\n"); } } void DestroyStack () { free(S.base); printf("OK\n"); } void ClearStack () { free(S.base); S.top=S.base; printf("OK\n"); } void StackEmpty () { if(S.top==S.base) printf("TRUE\n"); else printf("FALSE\n"); } void StackLength () { printf("%d\n",S.Length); } void GetTop () { if(S.top==S.base) printf("EORRO"); else { printf("%d\n",*(S.top-1)); } } void Push () { scanf("%d",S.top); *S.top++; S.Length++; printf("OK\n"); } void Pop () { if(S.top==S.base) { printf("NULL\n"); } else { S.Length--; S.top--; printf("OK\n"); } } void kTraverse () { if (S.top=S.base) { printf("STACK NULL"); } else { e=S.base; while (e<S.top) { printf("%d ",*e); e++; } printf("\n"); } } void main() {}