数据结构与算法分析——栈
来源:互联网 发布:wkwebview 加载本地js 编辑:程序博客网 时间:2024/06/05 08:05
栈
代码实现如下
Stack.h
#ifndef _Stack_Hstruct Node;typedef struct Node *PtrToNode;typedef PtrToNode Stack;typedef int ElementType;int IsEmpty(Stack S);Stack CreateStack(void);void Push(ElementType X, Stack S);void Pop(Stack S);ElementType Top(Stack S);#endif
Stack.c
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include "Stack.h"struct Node{ ElementType Element; PtrToNode Next;};void FatalError(const char *Str){ printf("%s\n",(*Str)); exit(-1);}int IsEmpty(Stack S){ return S->Next == NULL;}/* Create a empty Stack */Stack CreateStack(void){ Stack S; S = malloc(sizeof(struct Node)); if(S == NULL) FatalError("Out of space!!!\n"); S->Next = NULL; return S;}/* Push X into Stack S*/void Push(ElementType X, Stack S){ PtrToNode TmpCell; TmpCell = malloc(sizeof(struct Node)); if(TmpCell == NULL) FatalError("Out of space!!!\n"); else { TmpCell->Element = X; TmpCell->Next = S->Next; S->Next = TmpCell; }}ElementType Top(Stack S){ if(!IsEmpty(S)) return S->Next->Element; printf("IsEmpty Stack"); return 0;}void Pop(Stack S){ PtrToNode FirstCell; if(IsEmpty(S)) printf("Empty Stack\n"); else { FirstCell = S->Next; S->Next = FirstCell->Next; free(FirstCell); }}
0 0
- 数据结构与算法分析——栈
- 数据结构与算法分析——最大公约数
- 数据结构与算法分析——单链表
- 数据结构与算法分析-栈
- 数据结构与算法学习1——算法复杂度分析
- 数据结构与算法——1.4算法分析
- 数据结构与算法分析:栈与队列
- 数据结构与算法分析:栈与队列
- 数据结构算法与分析
- 数据结构与算法分析
- 数据结构与算法分析
- 数据结构与算法分析
- 数据结构与算法分析
- 数据结构与算法分析
- 数据结构与算法分析
- 数据结构与算法分析
- 《数据结构与算法分析》
- 数据结构与算法分析——快速排序
- PostgreSQL物理备份与恢复
- UVA - 514 Rails
- linux 常用命令
- 如何编写linux守护进程?
- CreateEvent/SetEvent/ResetEvent和WaitForSingleObject
- 数据结构与算法分析——栈
- iOS 给collectionView增加Header
- Puppet3在CentOS6.5集群下的安装
- 利用GDB进行多线程调试
- OutMan——Foundation框架中的常用结构体、NSNumber类和NSValue类
- MAC 版 sublime text 2 安装插件管理器
- 计算机组成和原理
- PAM-Linux可插拔认证模块(PAM)的配置文件、工作原理与流程
- DOM(二)-04-(示例-展开闭合列表2)