C数据结构-链栈
来源:互联网 发布:淘宝电影票能退吗 编辑:程序博客网 时间:2024/05/16 14:21
链栈
链栈的设计依赖于笔者之前设计的链表,详情请看《C数据结构-线性表之单链表 》。
#ifndef LINKEDSTACK_H#define LINKEDSTACK_H#include "LinkedList.h"typedef linked_list linked_stack;/** * 创建链表栈 * @return */linked_stack *linked_stack_create();/** * 入栈 * @param pstack 栈指针 * @param p 入栈元素的指针 * @return 成功:1,失败:0 */int linked_stack_push(linked_stack *pstack, elem_t *p);/** * 出栈 * @param pstack 栈指针 * @return 返回出栈元素的值 */elem_t linked_stack_pop(linked_stack *pstack);/** * 获取栈顶元素的值 * @param pstack * @return */elem_t linked_stack_top(linked_stack *pstack);/** * 判断栈是否为空 * @param pstack 栈指针 * @return 1为空,否则非空 */int linked_stack_empty(linked_stack *pstack);/** * 销毁栈 * @param pstack 栈指针 * @return 成功:1,失败:0 */int linked_stack_destroy(linked_stack *pstack);#endif // LINKEDSTACK_H
#include "LinkedStack.h"/** * 创建链表栈 * @return */linked_stack *linked_stack_create(){ return linked_list_create();}/** * 入栈 * @param pstack 栈指针 * @param p 入栈元素的指针 * @return 成功:1,失败:0 */int linked_stack_push(linked_stack *pstack, elem_t *p){ return linked_list_insert(pstack,p);}/** * 出栈 * @param pstack 栈指针 * @return 返回出栈元素的值 */elem_t linked_stack_pop(linked_stack *pstack){ elem_t temp; linked_list_remove(pstack,0,&temp); return temp;}/** * 获取栈顶元素的值 * @param pstack * @return */elem_t linked_stack_top(linked_stack *pstack){ elem_t temp; linked_list_get(pstack,0,&temp); return temp;}/** * 判断栈是否为空 * @param pstack 栈指针 * @return 1为空,否则非空 */int linked_stack_empty(linked_stack *pstack){ return (pstack->length == 0);}/** * 销毁栈 * @param pstack 栈指针 * @return 成功:1,失败:0 */int linked_stack_destroy(linked_stack *pstack){ return linked_list_destroy(pstack);}
阅读全文
0 0
- 数据结构 - 链栈(C)
- C语言数据结构-链栈
- 数据结构-链栈(C语言)
- C语言-数据结构-链栈
- C数据结构-链栈
- 数据结构(C实现)------- 链栈
- C++,数据结构
- 数据结构C
- 数据结构(C)
- 数据结构 - C语言版 - 链栈 所有基本操作
- 链栈,C++,数据结构王红梅版
- 数据结构(C#)--单链表
- 数据结构(C#)--单链表
- 插入排序 --C数据结构
- 冒泡排序 C数据结构
- 基数排序 C语言数据结构
- 数据结构(C++)--二叉树
- 链式队列(数据结构C#)
- select框默认选项为空白
- 怎样获得C币
- MATLAB R2016a Builder JA
- 《Linux系统管理》
- 专访阿里云闵万里:云上逐鹿,ET大脑要做行业化、垂直化的创新运用
- C数据结构-链栈
- 小故事,大道理
- 解密MySQL备份恢复的4种方法(转)
- “基于颜色属性直方图的尺度目标跟踪算法研究”阅读笔记
- leetcode 215. Kth Largest Element in an Array
- 【深入PHP 面向对象】读书笔记(十五)
- bzoj 1297: [SCOI2009]迷路
- 通过Apache转发和Tomcat共用80端口
- 高防服务器如何选择