C语言实现常用数据结构——栈
#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语言实现常用数据结构——栈的更多相关文章
- C语言实现常用数据结构——链表
#include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node *next; ...
- C语言实现常用数据结构——堆
#include<stdio.h> #include<stdlib.h> #define CAPACITY 20 /*堆有两个性质: * 1.结构性:堆必须是一颗完全二叉树 * ...
- C语言实现常用数据结构——图
#include<stdio.h> #include<stdlib.h> #define SIZE 20 #define LENGTH(a) (sizeof(a)/sizeof ...
- C语言实现常用数据结构——二叉树
#include<stdio.h> #include<stdlib.h> #define SIZE 10 typedef struct Tree { int data; str ...
- C语言实现常用数据结构——队列
#include<stdio.h> #include<stdlib.h> #define MAX_SIZE 10 /* 用一个动态数组来实现队列 */ typedef stru ...
- 数据结构——栈(C语言实现)
#include <stdio.h> #include <stdlib.h> #include<string.h> #include<malloc.h> ...
- C语言数据结构-栈的实现-初始化、销毁、长度、取栈顶元素、查找、入栈、出栈、显示操作
1.数据结构-栈的实现-C语言 #define MAXSIZE 100 //栈的存储结构 typedef struct { int* base; //栈底指针 int* top; //栈顶指针 int ...
- 1. C语言中的数据结构.md
C语言内建数据结构类型 整型 整型数据是最基本的数据类型,不过从整形出发衍生出好几种integer-like数据结构,譬如字符型,短整型,整型,长整型.他们都是最基本的方式来组织的数据结构,一般是几位 ...
- Java 集合框架(常用数据结构)
早在Java 2中之前,Java就提供了特设类.比如:向量(Vector).栈(Stack).字典(Dictionary).哈希表(Hashtable)这些类(数据结构)用来存储和操作对象组.虽然这些 ...
随机推荐
- java 保存和读取本地json文件
保存数据到本地文件 private void saveDataToFile(String fileName,String data) { BufferedWriter writer = null; F ...
- .net程序运行流程
程序员用.net开发的程序要在计算机上运行,首先程序经过编译后,会生成机器指令,一般以一个文件的形式保存,这个文件在外存储器上(存储器分外存与内存.外存:硬盘,U盘等:) 然后cpu会把硬盘上的文件读 ...
- 推荐一些C#相关的网站和书籍
1.http://msdn.microsoft.com/zh-CN/ 微软的官方网站,C#程序员必去的地方.那里有API开发文档,还有各种代码.资源下载. 2.http://social.msdn.m ...
- Android studio中的6大布局
1.相对布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...
- 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 ...
- HDU 3153 Pencils from the 19th Century(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153 Problem Description Before "automaton" ...
- string操作
常用的功能测试: #! -*- coding:utf-8 -*- import string s = 'Yes! This is a string' print '原字符串:' + s print ' ...
- 深入python3 (Dive Into Python 3) 在线阅读与下载
在线阅读:http://book.doucube.com/diveintopython3/ 中文版 下载地址:https://github.com/downloads/diveintomark/di ...
- js中的escape的用法汇总
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...
- [Unity3D]Unity3D叙利亚NGUI血液和技能的冷却效果
---------------------------------------------------------------------------------------------------- ...