
数据结构(天勤代码实现)
XYZHCS
这个作者很懒,什么都没留下…
展开
-
二叉树的创建与遍历
前序和中序、中序和后序可唯一确定一棵二叉树。前序和后序不可唯一确定一棵二叉树。#include<iostream>#include<stdlib.h>#define maxSize 100using namespace std;typedef struct BTNode{ char data; struct BTNode *lchild;...原创 2019-04-27 19:49:51 · 356 阅读 · 1 评论 -
图的非递归深度优先搜索(邻接表存储)
邻接表//边表typedef struct ArcNode { int adjvex; //该边所指向的结点的位置 struct ArcNode *nextarc; //指向下一条边的指针 int info; //该边的相关信息(如权值) }ArcNode;//顶点表typedef struct ...原创 2019-09-14 10:21:23 · 800 阅读 · 0 评论 -
弗洛伊德算法
#include<iostream>using namespace std;#define maxSize 99#define inf 999typedef struct{ int no; char info;}VertexType;typedef struct{ int edges[maxSize][maxSize]; int n,e; VertexTyp...原创 2019-08-29 08:59:33 · 1493 阅读 · 1 评论 -
二叉树的非递归遍历(二)之线索二叉树
中序线索二叉树的构造:typedef struct TBNode{ int data; int ltag,rtag; TBNode *lchild; TBNode *rchild;}TBTNode;//通过中序遍历对二叉树线索化 void InThread(TBTNode *p,TBTNode *&pre){ if(p!=NULL) { InThread(...原创 2019-08-17 08:48:19 · 869 阅读 · 0 评论 -
数组、矩阵、与广义表(三)
稀疏矩阵A、B以三元组存储 求: C=A+Bvoid add(int A[][3],int B[][3],int C[][3]){ int i=1,j=1,k=1,m; while(i<=A[0][0]&&j<=B[0][0]) if(A[i][1]==B[j][1]) { if(A[i][2]<B[j][2]) { ...原创 2019-08-13 08:42:31 · 160 阅读 · 0 评论 -
数组、矩阵、与广义表(二)
在一个二维数组中找出所在行所在列都最小或最大的元素:#include<iostream>using namespace std;#define maxSize 99void printmin(int A[][maxSize],int m,int n){ int i,j,k,min,minj; int flag; for(i=0;i<m;++i) { ...原创 2019-08-12 09:06:32 · 188 阅读 · 0 评论 -
数组、矩阵与广义表
移动数组中非零元素至数组的前端 :#include<iostream>using namespace std;void movelement(int a[],int n){ int i=-1,j,temp; for(j=0;j<n;++j) if(a[j]!=0) { ++i; if(i!=j) { temp=a[i]; a[i]...原创 2019-08-11 10:00:50 · 244 阅读 · 0 评论 -
二叉树的创建
前序、中序#include<iostream>#include<cstdlib>using namespace std;typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;BTNode *CreateBT(char pre[],...原创 2019-08-19 09:11:43 · 235 阅读 · 0 评论 -
串的模式匹配算法-KMP
#include<iostream>#include<cstdlib>#include<cstring>using namespace std;#define maxSize 99//所有字符串从下标1开始存储 typedef struct { char *ch; int length;}Str;void getnext(Str subs...原创 2019-08-09 10:06:28 · 244 阅读 · 0 评论 -
拓扑排序
#include<iostream>#include<cstdlib>#include<cstring> using namespace std;#define maxSize 100//边表typedef struct ArcNode { int adjvex; //该边所指向的结点的位置 struct A...原创 2019-05-23 21:40:49 · 222 阅读 · 0 评论 -
最短路径(迪杰斯特拉算法)
#include<iostream>using namespace std;#include<cstring>#define maxSize 100#define INF 0x3f3f3f3ftypedef struct { int no; //顶点编号 char info; //顶点其他信息 }VertexType;typed...原创 2019-05-23 20:58:49 · 1091 阅读 · 0 评论 -
最小生成树(库鲁斯卡尔算法)
#include<iostream>#include<algorithm>using namespace std;#define maxSize 100#define INF 0x3f3f3f3ftypedef struct { int no; //顶点编号 char info; //顶点其他信息 }VertexType;typ...原创 2019-05-23 20:57:14 · 766 阅读 · 5 评论 -
最小生成树(普里姆算法)
#include<iostream>using namespace std;#include<cstring>#define maxSize 100#define INF 0x3f3f3f3ftypedef struct { int no; //顶点编号 char info; //顶点其他信息 }VertexType;typed...原创 2019-05-23 20:56:12 · 891 阅读 · 0 评论 -
图的创建与遍历(邻接表存储方式)
#include<iostream>#include<cstdlib>#include<cstring> using namespace std;#define maxSize 100//边表typedef struct ArcNode { int adjvex; //该边所指向的结点的位置 struct A...原创 2019-05-22 21:28:05 · 2863 阅读 · 0 评论 -
二叉树的非递归遍历
#include<iostream>#include<stdlib.h>#define maxSize 100using namespace std;typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;void Visit(BTNo...原创 2019-04-27 21:00:34 · 186 阅读 · 0 评论 -
二叉树的层次遍历
#include<iostream>#include<stdlib.h>#define maxSize 100using namespace std;typedef struct BTNode{ char data; struct BTNode *lchild; struct BTNode *rchild;}BTNode;void Visit(BTNo...原创 2019-04-27 20:23:04 · 227 阅读 · 0 评论 -
栈与后缀表达式
#include<iostream>#define maxSize 100using namespace std;int op(int a,char Op,int b){ if(Op=='+') return a+b; if(Op=='-') return a-b; if(Op=='*') return a*b; if(Op=='/') { if(b==0) ...原创 2019-04-26 19:47:48 · 804 阅读 · 0 评论 -
直接插入排序(链表)
typedef struct LNode{ int data; struct LNode *next;}LNode;void CreateLink(LNode *&h,char R[],int n){ int i; LNode *s,*t; h=(LNode*)malloc(sizeof(LNode)); h->next=NULL; t=h; for(i=0...原创 2019-09-20 09:33:24 · 1499 阅读 · 0 评论