This commit is contained in:
hairrrrr
2020-04-21 12:56:34 +08:00
parent 88c8eb06ca
commit 1c26a8b1cf
2 changed files with 42 additions and 1 deletions

View File

@@ -1 +1,19 @@
不同的实现方式中 接口头文件和客户包含main函数的文件改变的很少
不同的实现方式中 接口头文件和客户包含main函数的文件改变的很少
我们一共使用了三种方式实现栈抽象数据类型:
1. 使用定长数组
2. 用动态数组
3. 使用链表
“最终形态”是基于链表的一些“改进”:
- 基于“不完整类型”的封装
- 使用宏来定义 PUBLIC 和 PRIVATE
- 使用不容易冲突的命名
- 提供错误处理的可能push 和 pop 函数返回值)
最后,本想通过改变 push 和 pop 来实现“通用抽象数据类型”,在修改程序时发现类型名还是不是很会处理,作罢。
可以参考下面的函数声明来完成它:
```c
bool stack_push(Stack s, void* i);
void* stack_pop(Stack s);
```

View File

@@ -0,0 +1,23 @@
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include"stackADT.h"
int main(void) {
Stack s1, s2;
s1 = create();
s2 = create();
push(s1, 1);
push(s1, 2);
printf("%d\n", pop(s1));
printf("%d\n", pop(s1));
destory(s1);
destory(s2);
return 0;
}