stack的数组实现(结构体封装版)
来源:互联网 发布:汉字域名百度收录吗 编辑:程序博客网 时间:2024/06/02 01:13
//栈的数组实现(结构体封装版)//-->栈被定义为结构体指针,具体数组也被定义为指针,栈动态新建#define MAXSIZE 100struct node{ int capacity;//栈容量 int top;//栈顶 int* array;//数组存具体栈元素};void Push(struct node* stack,int element){ if(stack->top==MAXSIZE-1){ printf("The stack is full!\n"); return; } stack->array[++stack->top]=element;}void Pop(struct node* stack){ if(stack->top!=-1) stack->top--;}void Top(struct node* stack){ if(stack->top!=-1) printf("%d\n",stack->array[stack->top]); else printf("Empty stack!\n");}void PopandTop(struct node* stack){ if(stack->top!=-1) printf("%d\n",stack->array[stack->top--]); else printf("Empty stack!\n");}int main(){ //栈的新建 struct node* stack; stack=(struct node* )malloc(sizeof(struct node)); //栈初始化(栈的array数组分配空间,但不用初始化) stack->capacity=MAXSIZE; stack->top=-1;//top初始化为-1 stack->array=(int *)malloc(sizeof(int)*MAXSIZE); //Push Push(stack,10); //Pop Pop(stack); //Top Top(stack); //PopandTop PopandTop(stack); return 0;}
1 0
- stack的数组实现(结构体封装版)
- stack的数组实现
- 动态数组实现的Stack类(过渡版)
- 数据结构栈stack的动态数组实现
- 静态数组实现的Stack类
- Stack简单实现向下增长数组版
- 用数组实现Stack
- 数组实现stack
- 数组实现stack
- 动态数组实现stack
- fortran动态结构体数组的实现
- Java封装栈工具类--利用数组实现栈结构
- 队列的结构体封装实现(啊哈算法版,以解密QQ号为例)
- 一个简单结构体实现封装
- C#调用C++封装的DLL传递结构体数组的终极解决方案
- 动态数组的Stack类模板的实现
- 栈 stack 用数组实现
- [数据结构]Stack(数组)实现
- rmq-st算法<区间最大最小>(hdu 5875)
- idea不支持泛型
- MSSQL_连接异常_网络连接异常(无法连接到服务器)_无法连接到WMI提供程序
- Logcat查看/输出日志信息
- lightoj 1002 - Country Roads(最短路变形)
- stack的数组实现(结构体封装版)
- 笔试选择题二十八
- 虚函数
- Linux中如何替换文件名中的空格
- POJ - 1742 Coins(多重背包)@
- 对象如何持久化(用json_encode)?
- Python-2
- Matlab中二进制数据文件的读写
- 记录Ubuntu的一些小常识