Data Structure and Algorithms
文章平均质量分 75
亚尔诺炽焰
这个作者很懒,什么都没留下…
展开
-
[数据结构] 队列的循环数组实现
当用数组表示队列时,可以把数组看成原创 2014-11-19 20:09:42 · 813 阅读 · 0 评论 -
[数据结构] 图的邻接矩阵深度优先搜索
无向图如上所示依次输入图的信息#include using namespace std; #define MAX_V 100 //定义最大顶点个数#define INF 1000 //表示正无穷 typedef struct VertexType{ int number;//顶点标号};//顶点类型typedef struct MGraph//图的定义{原创 2015-02-03 18:18:12 · 637 阅读 · 0 评论 -
[数据结构] 图的邻接矩阵广度优先搜索
无向图如上所示依次输入图的信息#include #include using namespace std; #define MAX_V 100 //定义最大顶点个数#define INF 1000 //表示正无穷 typedef struct VertexType{ int number;//顶点标号};//顶点类型typedef struct MGraph原创 2015-02-03 22:11:25 · 624 阅读 · 0 评论 -
[数据结构] 图的Prim算法实现
图的Prim算法实现最小生成树#include using namespace std; #define MAX_V 100 //定义最大顶点个数#define INF 1000 //表示正无穷 typedef struct VertexType{ int number;//顶点标号};//顶点类型typedef struct MGraph//图的定义{原创 2015-02-13 15:02:58 · 679 阅读 · 0 评论 -
[数据结构] 图的Kruskal算法实现
#include using namespace std; #define MAX_V 100 //定义最大顶点个数#define INF 1000 //表示正无穷 typedef struct VertexType{ int number;//顶点标号};//顶点类型typedef struct MGraph//图的定义{ int matrix[MAX_V原创 2015-03-04 20:01:38 · 647 阅读 · 0 评论 -
[数据结构] Floyd算法计算图的中心点
#include using namespace std; #define MAX_V 100 //定义最大顶点个数#define INF 10000 //表示正无穷 typedef struct MGraph//图的定义{ //int matrix[MAX_V][MAX_V];//邻接矩阵,带权值可存权值如下 int weight[MAX_V][MAX_V];//原创 2014-11-11 14:46:10 · 1900 阅读 · 0 评论 -
[数据结构] 图的邻接表拓扑排序实现
#include #include #include #define Max_V 100 // 最大顶点数 using namespace std;typedef struct node{ int vtex; //邻接点 int weight; //权值 struct node *next; //链域 } EdgeNode;原创 2015-03-09 19:59:29 · 1781 阅读 · 1 评论 -
[数据结构] 冒泡排序,插入排序,选择排序
冒泡排序, 插入排序,选择排序#include #define MAX_SIZE 100using namespace std;typedef int keytype;typedef struct records //排序类型 { keytype key; //fields other; };typedef records LIST[MAX_SI原创 2015-04-01 19:20:43 · 411 阅读 · 0 评论 -
[数据结构] 快速排序算法
快速排序算法初步描述如下:(1)if(A[i] ~ A[j] 至少包含两个不同的关键字)(2)令v的值为分块中最左两个不同关键字的较大值(3)对A[i],……A[j]中的元素进行置换: 在i+1到j中确定一个k,使A[i],……A[k-1]的关键字都小于v, A[k],……A[j]的关键字都不小于v;(4)QuickSort(i, k-1原创 2015-04-01 19:28:16 · 505 阅读 · 0 评论 -
[数据结构] 归并排序算法
#include #define MAX_SIZE 100using namespace std;typedef int keytype; typedef struct records //排序类型 { keytype key; //fields other; };typedef records LIST[MAX_SIZE]; //排序数组/*设A原创 2015-04-02 21:19:56 · 540 阅读 · 0 评论 -
[转载] SBT(Size Balanced Tree)
[cpp] view plain copy print?/************************************************* 数据结构: SBT(Size Balanced Tree),又称傻逼树; 数据域: 值域key,左孩子left,右孩子right,保持平衡的size; 性质: 每棵子树的大小转载 2016-03-14 01:03:32 · 381 阅读 · 0 评论 -
[数据结构] 堆排序算法
#include #define MAX_SIZE 100using namespace std;typedef int keytype; typedef struct records //排序类型 { keytype key; //fields other; };typedef records LIST[MAX_SIZE]; //排序数组void S原创 2015-04-09 23:55:44 · 559 阅读 · 0 评论 -
[数据结构] 基数排序算法
#include #include using namespace std;int Radix(int k, int p)//求出每个数据的第pass位数字 { int power, i; power = 1; for(i = 1; i { power = power*10; } ret原创 2015-04-10 21:13:04 · 543 阅读 · 0 评论 -
[数据结构] 队列的指针实现
#include using namespace std;typedef int element_type;struct celltype{ element_type element; struct celltype *next;};struct QUEUE{ celltype *front; celltype *rear;};void MakeNull(QUEU原创 2014-11-19 18:40:51 · 927 阅读 · 0 评论 -
[转载] 线索二叉树的实现
输入 A B C D E F G H I J以先序遍历,用“#”表示转载 2014-12-03 20:37:08 · 488 阅读 · 0 评论 -
[数据结构] 二叉树的递归与非递归遍历
输入原创 2014-11-25 15:06:08 · 587 阅读 · 0 评论 -
韩信点兵算法
韩信点兵是一个有趣的猜数游戏。如果你随便拿一把蚕豆(数目约在100粒左右),先3粒3粒地数,直到不满3粒时,把余数记下来;第二次再5粒5粒地数,最后把余数记下来;第三次是7粒一数,把余数记下来。然后根据每次的余数,就可以知道你原来拿了多少粒蚕豆了。不信的话,你还可以试验一下。例如,假如3粒一数余1粒,5粒一数余2粒,7粒一数余2粒,那么,原有蚕豆有多少粒呢? 这类题目看起来是很难计算的,可是我转载 2015-07-15 10:35:48 · 2432 阅读 · 0 评论 -
[数据结构] 单向链表
#include #include struct link *AppendNode(struct link *head,FILE *fp);struct link *DeleteNode(struct link *head, int nodeData);struct link *InsertNode(struct link *head, int nodeData);stru原创 2014-09-17 21:36:34 · 691 阅读 · 0 评论 -
[转载] 线性表的数组实现
/*对于线性结构,有两种保存的方法,一种是使用C语言中内置的数组,这样的结构成为顺序表;另一种使用指针,这样的结构成为链表。对于线性结构,有12种基本的操作,分别是:初始化、删除、清空、判断是否为空、遍历、求表的长度、求某个元素在表中的位置、返回特定序号的元素、求某个元素的前一个元素、求某个元素的后一个元素、插入一个元素、删除一个元素。这一小节介绍如何利用数组实现线性表。*//*再插入转载 2014-10-10 18:31:21 · 746 阅读 · 0 评论 -
[数据结构] 链表实现多项式
#include using namespace std;struct polynode{ double coef; int exp; struct polynode *next;};struct polynode *CreatNode();struct polynode *AddNode(struct polynode *p,struct polynode *q);voi原创 2014-10-15 16:32:07 · 883 阅读 · 0 评论 -
[数据结构] 单向链表拆分成两个循环链表
#include using namespace std;struct node { int data; struct node *next;} ;struct node *CreatNode();void DisplayNode(struct node *head);void SeparateNode(struct node *head,struct node *&p,stru原创 2014-10-16 20:57:32 · 1733 阅读 · 0 评论 -
[数据结构] 双向链表的实现
#include #include typedef int Elementtype;struct celltype{ Elementtype element; struct celltype *next; struct celltype *previous;} ;typedef celltype *position;position CreateNode(positi原创 2014-10-16 21:15:51 · 697 阅读 · 0 评论 -
[数据结构] 二叉树的操作实现
#include #include #define MAX 100typedef int Elementtype;struct node{ struct node *lchild; struct node *rchild; Elementtype data;};typedef node *BTREE;BTREE CreateTree();int IsEmpty(BT原创 2014-10-18 17:26:23 · 1292 阅读 · 3 评论 -
[转载] AOE网关键路径的计算
认识AOE网 有向图中,用顶点表示活动,用有向边表示活动之间开始的先后顺序,则称这种有向图为AOV网络;AOV网络可以反应任务完成的先后顺序(拓扑排序)。 在AOV网的边上加上权值表示完成该活动所需的时间,则称这样的AOV网为AOE网,如下图: 图中,顶点表示事件(能被触发,两特征属性:最早发生时间Ve(j);最晚发生时间Vl(j)),边表示活动(能被开转载 2014-11-07 23:47:45 · 957 阅读 · 0 评论 -
[数据结构] 栈的数组实现
#include using namespace std; #define maxlength 100typedef int Elementtype;struct STACK{ int top; Elementtype elements[maxlength];};//以数组最大段(下标)为栈底,top依次上升 void MakeNull(STACK *S)//MakeNu原创 2014-11-18 14:10:08 · 488 阅读 · 0 评论 -
[数据结构] 邻接矩阵实现Dijkstra算法
#include using namespace std; #define MAX_V 100 //定义最大顶点个数#define INF 1000 //表示正无穷 typedef struct VertexType{ int number;//顶点标号 //int weight;};//顶点类型typedef struct MGraph//图的定义{原创 2014-11-18 14:14:30 · 1274 阅读 · 0 评论 -
[数据结构] 栈的指针实现
#include using namespace std;typedef int element_type;struct node{ element_type val; struct node *next;} ;typedef node *STACK;void MakeNull(STACK S)//建立新栈,并使其头结点为空 { S = new node; S->n原创 2014-11-18 15:18:00 · 891 阅读 · 0 评论 -
[数据结构] 二叉树的等价判断与复制
输入 A B C D E F G H I J以先序遍历,用“#”表示原创 2014-12-03 21:40:13 · 695 阅读 · 0 评论 -
分数化小数
输入正整数a,b,c,输出a/b的小数形式,精确到小数点后c位。a,b题目很简单,但是用数组表示高精度数的思想很好#include using namespace std;int main(){ int a,b,c; cin >> a >> b >> c; int remainder; int integer; integer原创 2015-07-15 16:01:43 · 639 阅读 · 0 评论