mirror of
https://github.com/hairrrrr/C-CrashCourse.git
synced 2026-02-03 02:33:16 +08:00
4-21
This commit is contained in:
@@ -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);
|
||||
```
|
||||
23
code/practise/19 程序设计/01 栈的实现/02 栈抽象数据类型/stackclient.c
Normal file
23
code/practise/19 程序设计/01 栈的实现/02 栈抽象数据类型/stackclient.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user