#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. java 保存和读取本地json文件

    保存数据到本地文件 private void saveDataToFile(String fileName,String data) { BufferedWriter writer = null; F ...

  2. .net程序运行流程

    程序员用.net开发的程序要在计算机上运行,首先程序经过编译后,会生成机器指令,一般以一个文件的形式保存,这个文件在外存储器上(存储器分外存与内存.外存:硬盘,U盘等:) 然后cpu会把硬盘上的文件读 ...

  3. 推荐一些C#相关的网站和书籍

    1.http://msdn.microsoft.com/zh-CN/ 微软的官方网站,C#程序员必去的地方.那里有API开发文档,还有各种代码.资源下载. 2.http://social.msdn.m ...

  4. Android studio中的6大布局

    1.相对布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...

  5. Method and apparatus for establishing IEEE 1588 clock synchronization across a network element comprising first and second cooperating smart interface converters wrapping the network element

    Apparatus for making legacy network elements transparent to IEEE 1588 Precision Time Protocol operat ...

  6. HDU 3153 Pencils from the 19th Century(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153 Problem Description Before "automaton" ...

  7. string操作

    常用的功能测试: #! -*- coding:utf-8 -*- import string s = 'Yes! This is a string' print '原字符串:' + s print ' ...

  8. 深入python3 (Dive Into Python 3) 在线阅读与下载

    在线阅读:http://book.doucube.com/diveintopython3/  中文版 下载地址:https://github.com/downloads/diveintomark/di ...

  9. js中的escape的用法汇总

    js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...

  10. [Unity3D]Unity3D叙利亚NGUI血液和技能的冷却效果

    ---------------------------------------------------------------------------------------------------- ...