#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);
}

C语言实现常用数据结构——栈的更多相关文章

  1. C语言实现常用数据结构——链表

    #include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node *next; ...

  2. C语言实现常用数据结构——堆

    #include<stdio.h> #include<stdlib.h> #define CAPACITY 20 /*堆有两个性质: * 1.结构性:堆必须是一颗完全二叉树 * ...

  3. C语言实现常用数据结构——图

    #include<stdio.h> #include<stdlib.h> #define SIZE 20 #define LENGTH(a) (sizeof(a)/sizeof ...

  4. C语言实现常用数据结构——二叉树

    #include<stdio.h> #include<stdlib.h> #define SIZE 10 typedef struct Tree { int data; str ...

  5. C语言实现常用数据结构——队列

    #include<stdio.h> #include<stdlib.h> #define MAX_SIZE 10 /* 用一个动态数组来实现队列 */ typedef stru ...

  6. 数据结构——栈(C语言实现)

    #include <stdio.h> #include <stdlib.h> #include<string.h> #include<malloc.h> ...

  7. C语言数据结构-栈的实现-初始化、销毁、长度、取栈顶元素、查找、入栈、出栈、显示操作

    1.数据结构-栈的实现-C语言 #define MAXSIZE 100 //栈的存储结构 typedef struct { int* base; //栈底指针 int* top; //栈顶指针 int ...

  8. 1. C语言中的数据结构.md

    C语言内建数据结构类型 整型 整型数据是最基本的数据类型,不过从整形出发衍生出好几种integer-like数据结构,譬如字符型,短整型,整型,长整型.他们都是最基本的方式来组织的数据结构,一般是几位 ...

  9. Java 集合框架(常用数据结构)

    早在Java 2中之前,Java就提供了特设类.比如:向量(Vector).栈(Stack).字典(Dictionary).哈希表(Hashtable)这些类(数据结构)用来存储和操作对象组.虽然这些 ...

随机推荐

  1. CentOS 7 部署 ASP.NET Core 应用程序

    原文:CentOS 7 部署 ASP.NET Core 应用程序 看了几篇大牛写的关于 Linux 部署 ASP.NET Core 程序的文章,今天来实战演练一下.2017年最后一个工作日,提前预祝大 ...

  2. [Scikit-Learn] - 数据预处理 - 归一化/标准化/正则化

    reference: http://www.cnblogs.com/chaosimple/p/4153167.html 一.标准化(Z-Score),或者去除均值和方差缩放 公式为:(X-mean)/ ...

  3. Java--ConcurrentHashMap原理分析

    一.背景: 线程不安全的HashMap     因为多线程环境下,使用Hashmap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap.   效率低下的H ...

  4. OpenGL中GLSL渲染茶壶光照完整程序

    顶点着色器VertexShader.txt: uniform vec3 lightposition;//光源位置 uniform vec3 eyeposition;//相机位置 uniform vec ...

  5. Linux下编译,要下载tar.xz,而不要下载zip,因为换行的编码不一样,对.h.cpp没有影响,但是对脚本有影响 good

    原因是 在win下编辑的时候,换行结尾是\n\r , 而在linux下 是\n,所以才会有 多出来的\r但是这个我是直接下载的官网文件解压的,没有动过啊. 破案了. linux下编译要下 .tar.x ...

  6. 学习vi和vim编辑(4):高速移动定位

    平时.第一步是编辑文本需要做将光标移动到需要编辑.因此,根据需要,将光标移动到目标数字键来编辑文本的速度在一定程度上. 一篇文章.主要介绍怎样高速移动光标. 依据屏幕来移动: 在一个有几千行文本的文件 ...

  7. Leetcode dfs Combination Sum

    Combination Sum Total Accepted: 17319 Total Submissions: 65259My Submissions Given a set of candidat ...

  8. 微信小程序之商品属性分类

    所提及的购物数量的加减,现在说说商品属性值联动选择. 为了让同学们有个直观的了解,到电商网截了一个图片,就是红圈所示的部分 现在就为大家介绍这个小组件,在小程序中,该如何去写 下图为本项目的图: wx ...

  9. top(k,n)—db kernel队解题思路

    0. 比赛 公司里的第三届XX中间件性能挑战赛 我和另外两个P5组队参加,队名为"db kernel".最后获得了第八,应该是P5里的最高排名. 以下简单扼要地介绍一下题目,以及我 ...

  10. BZOJ 3329 Xorequ 数字DP+矩阵乘法

    标题效果:特定n,乞讨[1,n]内[1,2^n]差多少x满足x^3x=2x x^3x=2x相当于x^2x = 3x 和3x=x+2x 和2x=x<<1 因此x满足条件IFFx&(x ...