数据结构与算法分析——c语言描述 练习3.23 答案
这道题还是挺有意思的。第三个栈从中间开始,假如有冲突的时候还剩空位时候移动第三个栈到栈1和栈2顶端的中心。
要注意的是如何判断整个是否满了,以及每个栈是否能再继续进栈。第三个栈有些特殊。
编程很多时候并不能一步到位,需要不断debug,然后不停更改。当然一开始的思路方向是很重要的。
stack.h
typedef int ElementType;
#ifndef _stack_h
#define _stack_h
struct StackRecord;
typedef struct StackRecord *Stack;
int IsEmpty1(Stack s);
int IsEmpty2(Stack s);
int IsEmpty3(Stack s);
int IsFull(Stack s);
Stack CreateStack(int MaxElements);
void DisposeStack(Stack s);
void MakeEmpty1(Stack s);
void MakeEmpty2(Stack s);
void MakeEmpty3(Stack s);
void Push1(ElementType X, Stack s);
void Push2(ElementType X, Stack s);
void Push3(ElementType X, Stack s);
ElementType Top1(Stack s);
ElementType Top2(Stack s);
ElementType Top3(Stack s);
void Pop1(Stack s);
void Pop2(Stack s);
void Pop3(Stack s);
ElementType TopAndPop1(Stack s);
ElementType TopAndPop2(Stack s);
ElementType TopAndPop3(Stack s);
//void debug(Stack