• 约 1 分钟

数据结构·复习卡片

二叉树的性质 ? 二叉树的性质

顺序栈 ? 结构描述:

#define MaxSize 50
typedef struct {
	ElemType data[MaxSize];
	int top;
} SqStack;

初始化:

void InitStack(SqStack *S) {
	S->top=-1;
}

判栈空:

bool StackEmpty(const SqStack *S) {
	if (S->top==-1)
		return true;
	else
		return false;
}

进栈:

bool Push(SqStack *S, ElemType x) {
	if (S->top==MaxSize-1)
		return false;
	S->data[++S->top] = x;
	return true;
}

出栈:

bool Pop(SqStack *S, ElemType *x) {
	if (S->top==-1)
		return false
	*x = S->data[S->top--];
	return true;
}

读栈顶元素:

bool GetTop(SqStack S, ElemType *x) {
	if (S->top==-1)
		return false;
	*x = S->data[S->top];
	return true;
}

链栈 ? 结构描述:

typedef struct {
	struct LNode *top;
	int height;
} LnStack;
林威
林威 咖味十足的软件工程师