C封装基于双向链表的栈对象
DoubleLinkedListStack双链栈
栈的结点数据结构定义如下:
1 | typedef int DLLSElemType; |
栈的对象数据结构定义如下:
1 | typedef struct DLLStack{ |
DLLStack.c
1 | #include <stdio.h> |
DLLStack.h
1 | /* Define to prevent recursive inclusion -------------------------------------*/ |
为了方便在其他的工程代码里对不同元素类型使用DLLStack,我把ElemTypeDefine抽取出来单独放在一个头文件里。这样,想要适用不同元素类型的DLLStack,只要修改ElemTypeDefine.h里的 DLLSElemType定义即可。默认的元素类型为int。
ElemTypeDefine.h文件
1 | /* Define to prevent recursive inclusion -------------------------------------*/ |
testDLLStack.c文件
1 | #include <stdio.h> |
编译:
1 | gcc DLLStack.c testDLLStack.c -o testDLLStack |
执行testDLLStack:
1 | is DLLStack empty:1 |
本文标题:C封装基于双向链表的栈对象
文章作者:Mr Bluyee
发布时间:2018-09-26
最后更新:2019-07-15
版权声明:The author owns the copyright, please indicate the source reproduced.