链栈的基本操作
来源:互联网 发布:国际贸易统计数据库 编辑:程序博客网 时间:2024/04/25 06:53
链栈的基本操作实现代码如下:
#include<iostream>
using namespace std;
#define TRUE 1
#define FALSE 0
//链栈的结构
typedef struct node
{
int data;
struct node *next;
}LinkStackNode;
typedef LinkStackNode *LinkStack;
//链栈进栈
int Push(LinkStack top, int x)//将数据元素x压入栈top中
{
LinkStackNode *temp;
temp = (LinkStackNode *)malloc(sizeof(LinkStackNode));
if (temp==NULL)//申请空间失败
{
return FALSE;
}
temp->data= x;
temp->next = top->next;
top->next = temp;//修改当前栈顶指针
return TRUE;
}
//链栈出栈
int Pop(LinkStack top, int *x)//将栈top的栈顶元素弹出,放到x所指的存储空间中
{
LinkStackNode *temp;
temp = top->next;
if (temp == NULL)//栈为空
{
return FALSE;
}
top->next = temp->next;
*x=temp->data ;
free(temp);//释放存储空间
return TRUE;
}
本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1772833
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 链栈的基本操作
- 栈的基本操作
- 栈的基本操作
- 栈 的基本操作。
- 栈的基本操作
- 栈的基本操作
- 栈的基本操作
- 栈的基本操作
- 栈的基本操作
- 栈的基本操作
- win10系统桌面图标变为白色方框和去除桌面图标快捷方式小箭头的方法
- 顺序栈的基本操作:初始化、进栈、出栈、读栈顶元素
- 多栈共享技术,双端栈的初始化、进栈、出栈操作
- 链队列的初始化、入队、出队等操作实现
- 循环队列的初始化、入队、出队等基本操作
- 链栈的基本操作
- 多栈运算
- Flash的按钮链接在网页的中的使用
- 汉诺塔问题的递归解法
- 求f(k)=k^k(k=1...n)的前n项和
- 二分查找算法的递归、循环实现及其缺陷
- 稀疏矩阵的列序递增法和一次定位快速转置法
- 二叉树的先序、中序、后序遍历等基本操作c++实现
- 文本处理,将交互组数据转化成邻接矩阵