C语言实现常用数据结构——栈
2024-08-24 14:46:51
#include<stdio.h>
#include<stdlib.h>
//用链表实现栈
typedef struct Node {
int data;
struct Node *next;
} node; int IsEmpty(node *p) {
return p->next==NULL;
} node *CreateStack() {
node *p=(node*)malloc(sizeof(node));
p->next=NULL;
return p;
} node *Push(node *p,int x) {
node *TmpCell=(node*)malloc(sizeof(node));
TmpCell->data=x;
TmpCell->next=p->next;
p->next=TmpCell;
return p;
} void Pop(node *p) {
node *cell;
if(p->next==NULL) {
printf("error,-1");
} else {
cell=p->next;
p->next=cell->next;
free(cell);
}
} void display(node *p) {
node *temp=p;
while(temp->next) {
printf("%d",temp->next->data);
temp=temp->next;
}
printf("%c",'\n');
} main() {
node *p=CreateStack();
Push(p,);
Push(p,);
Push(p,);
Push(p,);
display(p);
Pop(p);
display(p);
Pop(p);
display(p);
}
最新文章
- MySQL5.0安装图解
- 【转载】RMAN备份保留策略设置相关命令
- Use getopt() &; getopt_long() to Parse Arguments
- Javascript输出表格
- 利用Shell命令获取IP地址
- C与C++存储空间布局
- DrawDibDraw函数的使用方法
- iOS真机测试种可能遇到的问题
- zabbix-web界面图形中文乱码解决方法
- 开源libusb驱动的libwdi驱动安装API库和zadig.exe安装UI应用程序的编译和调试
- web page diagnostics
- org.apache.commons.lang下的工具类
- 微信小程序弹出和隐藏遮罩层动画以及五星评分
- 【java】-- 多线程之间实现通讯
- storcli 简易使用介绍
- Spark之GraphX的Graph_scala学习
- lightoj 1341 Aladdin and the Flying Carpet(算术基本定理)题解
- Android SDK的安装与环境配置
- Android Eclipse 开发环境搭建
- NOIP Mayan游戏
热门文章
- 使用UISegementControl实现简易Tomcat程序
- WPF中PasswordBox控件的Password属性的数据绑定
- C# .NET数据库操作
- vue 使用jquery (全局)
- 配置mysql 及 设置密码
- Information Centric Networking Based Service Centric Networking
- [Unity3D]Unity3D游戏开发Lua随着游戏的债券(在)
- ASP.NET Core 中间件 - ASP.NET Core 基础教程 - 简单教程,简单编程
- wpf Storyboard 不存在可解析名称“ ”的适用名称领域 No applicable name scope exists to resolve the name
- CSS position财产