本文使用了链栈,相对于顺序栈,链栈具有通常情况下不会出现栈满的情况
链栈和链表很相似。
由于栈的先进后出特性,栈在很多地方都很适用,比如
括号匹配,算术表达式求职,路径判断(走迷宫游戏)高级点的有函数的调用等等
总之,经常要接触栈
尤其是现在作为学生,一定要把数据结构这一块给弄好
作为链栈,那么还是需要定义一下存储数据的节点(数据对象)
typedef struct node{
Elem data;
struct node *next;
}SNode;
那么对应的操作(数据操作)有:initialize(),pop,push,isEmpty(), getLength(),destory()等
在贴代码完代码后,将总结一下本次编程过程中积累的几个经验
stack.h
/*
*用链表实现栈,实现操作push、pop、isEmpty、getLength等
*栈的top指针始终指向top节点,
*SCU liujinmou
*/
#include
#include
#define Elem int
//define the node of the stack
//we still use a struct to store the node
typedef struct node{
Elem data;
struct node *next;
}SNode;
//define the