
数据结构
文章平均质量分 81
minyuanxiani
这个作者很懒,什么都没留下…
展开
-
数据结构——广度优先搜索求点到点的最短路劲
#include using namespace std;#include #include #define OK 1#define NULL 0#define MAX_VERTEX_NUM 20 // 最大顶点数typedef char VertexType;typedef int VRType;typedef int InforType;原创 2013-09-04 08:45:29 · 1271 阅读 · 0 评论 -
数据结构——邻接矩阵的最小生成Prim算法
#include #include using namespace std; #define MAX_VERTEX_NUM 10 //最大顶点个数#define INFINITY 32768 typedef char VerType;typedef int VRType;typedef struct{ VerTyp原创 2013-09-03 16:55:32 · 710 阅读 · 0 评论 -
数据结构——求邻接矩阵表示的图的关节点
#include using namespace std;#include #include #define OK 1#define NULL 0#define MAX_VERTEX_NUM 20 // 最大顶点数//全局变量int count; int visited[MAX_VERTEX_NUM]; //记录节点访问的顺序in原创 2013-09-03 16:53:41 · 1733 阅读 · 1 评论 -
数据结构——邻接矩阵表示的图的Dijkstra算法
#include #include using namespace std; #define MAX_VERTEX_NUM 10 //最大顶点个数#define TRUE 1#define FALSE 0#define INFINITY 32767 /* 用整型最大值代替∞ */typedef char VERTYPE;ty原创 2013-09-03 16:51:39 · 1586 阅读 · 0 评论 -
数据结构——前序线索化二叉树
#include using namespace std;typedef enum PointerTag {Link,Thread}; //Link==0,Thread==1;线索typedef struct treenode{ struct treenode *left; char data; struct treenod原创 2013-09-04 09:12:19 · 931 阅读 · 0 评论 -
数据结构——快速排序
//快速排序算法#include #include #include using namespace std;//快速排序int Partition(int num[],int i,int j) //调用Partition(num,low,high)时,对num[low...high]做划分,并返回基准记录的位置 { int pivot=num[原创 2013-09-05 10:37:16 · 563 阅读 · 0 评论 -
数据结构——图的邻接矩阵的深度优先搜索
#include using namespace std; #define MAX_VERTEX_NUM 10 //最大顶点个数typedef char VERTYPE;typedef struct{ VERTYPE vexs[MAX_VERTEX_NUM]; //顶点向量 int visited[MAX_V原创 2013-09-04 09:03:16 · 879 阅读 · 0 评论 -
数据结构——图的邻接表表示法
#include using namespace std;#include #include #define OK 1#define NULL 0#define MAX_VERTEX_NUM 20 // 最大顶点数typedef char VertexType;typedef int VRType;typedef int InforType;原创 2013-09-04 09:05:13 · 782 阅读 · 0 评论 -
数据结构——树的还在兄弟表示法
#include using namespace std;typedef struct CSNode{ char data; struct CSNode * firstchild , * nextsibling ;}* CSTree;//================================================原创 2013-09-04 09:09:12 · 635 阅读 · 0 评论 -
数据结构——深度优先搜索求点到点的一般路径
#include using namespace std;#include #include #define OK 1#define NULL 0#define MAX_VERTEX_NUM 20 // 最大顶点数typedef char VertexType;typedef int VRType;typedef int InforType;原创 2013-09-04 08:59:11 · 659 阅读 · 0 评论 -
数据结构——邻接矩阵的最小生成树Kruskal算法
#include #include using namespace std; #define MAX_VERTEX_NUM 10 //最大顶点个数#define INFINITY 32768 typedef char VerType;typedef int VRType;typedef struct{ VerTyp原创 2013-09-03 16:55:30 · 2239 阅读 · 0 评论 -
数据结构——次优查找树的构造
#include #include #include using namespace std;typedef struct treenode{ struct treenode *left; char data; int weight; struct treenode *right;}Treenode,* Treep;int l原创 2013-09-03 16:46:31 · 1273 阅读 · 0 评论 -
数据结构——哈希表/散列表
#include "stdio.h"#include "stdlib.h"#define SUCCESS 1#define UNSUCCESS 0#define DUPLICATE -1#define OK 1#define ERROR -1#define EQ(a,b) ((a)==(b))#define LT(a,b) ((a)< (b))#define原创 2013-09-03 16:32:15 · 670 阅读 · 0 评论 -
数据结构——链式基数排序
#include using namespace std;#define MAX_NUM_OF_KEY 8 //关键字项数的最大值#define RADIX 10 //关键字基数,此时是十进制整数的基数#define MAX_SPACE 10000typedef int DataType ;typedef struct {原创 2013-09-03 16:43:00 · 1478 阅读 · 0 评论 -
数据结构——后序线索化二叉树
#include using namespace std;typedef enum PointerTag {Link,Thread}; //Link==0,Thread==1;线索typedef struct treenode{ struct treenode *left; char data; struct treenod原创 2013-09-04 09:13:30 · 1326 阅读 · 1 评论 -
数据结构——串的链式存储
#include using namespace std;typedef struct node{ char data; struct node *next;}LinkStrNode;typedef LinkStrNode * LinkString; //链式串的指针//初始化串void Init_LinkString(LinkStri原创 2013-09-05 10:22:20 · 1119 阅读 · 0 评论 -
数据结构——线性表
#include using namespace std;#define Listsize 100 //表空间的大小可根据实际需要而定,这里假设为100typedef int DataType; //DataType的类型可根据实际情况而定,这里假设为inttypedef struct { DataType data[Listsize]原创 2013-09-05 10:29:31 · 611 阅读 · 0 评论 -
数据结构——直接插入排序
//直接插入排序#include using namespace std;void Insertsort(int num[],int n){ int i,j; int temp; for(i=1;i<n;i++) { temp=num[i]; j=i-1; //从右向左寻找num[i]的插入位置 while(j>=0 && temp<num[原创 2013-09-05 10:38:52 · 622 阅读 · 0 评论 -
数据结构——中序线索化二叉树
#include using namespace std;typedef enum PointerTag {Link,Thread}; //Link==0,Thread==1;线索typedef struct treenode{ struct treenode *left; char data; struct treenod原创 2013-09-04 09:14:07 · 756 阅读 · 0 评论 -
数据结构——键树之双链表
#include "stdio.h"#include "stdlib.h"#include "string.h"#define OK 1#define ERROR 0typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等typedef int Boolean; // Boolean是布尔类型,其值是TRUE或false原创 2013-09-03 16:40:20 · 773 阅读 · 0 评论 -
数据结构——邻接表表示的图的拓扑排序算法
#include using namespace std;#include #include #define OK 1#define NULL 0#define MAX_VERTEX_NUM 20 // 最大顶点数typedef char VertexType;typedef int VRType;typedef int InforType;ty原创 2013-09-03 16:50:20 · 1095 阅读 · 0 评论 -
数据结构——树的双亲表示法
#include using namespace std;#define MAX_TREE_SIZE 100typedef struct //节点结构{ char data; int parent; //双亲位置域}PTNode;typedef struct //树结构{ PTNode node[原创 2013-09-04 09:09:44 · 3944 阅读 · 0 评论 -
数据结构——KMP算法
#include using namespace std;#define MaxStrSize 256typedef unsigned char MyString[MaxStrSize+1]; //0号单元存放串的长度int next[5];/* 掩饰符号类型。例如当需要定义多个包含80个元素的数组a,b,c时,可以这样定义: typede原创 2013-09-04 09:15:48 · 561 阅读 · 0 评论 -
数据结构——链式二叉树
#include using namespace std;typedef struct treenode{ struct treenode *left; char data; struct treenode *right;}Treenode,* Treep;//初始化二叉树void init_tree(Treep &root){原创 2013-09-04 09:20:37 · 590 阅读 · 0 评论 -
串的顺序存储
#include using namespace std;#define MaxStrSize 256typedef struct mystring{ char str[MaxStrSize]; int len;}MyString; /* 掩饰符号类型。例如当需要定义多个包含80个元素的数组a,b,c时,可以这样定义:原创 2013-09-05 10:26:08 · 532 阅读 · 0 评论 -
数据结构——链队列
#include using namespace std;typedef struct qnode{ int data; struct qnode * next; }Qnode, * Queueptr; // 创建链 Qnode是struct qnode的别名,Queueptr是struct qnode *的别名typedef原创 2013-09-05 10:32:20 · 893 阅读 · 0 评论 -
数据结构——希尔排序
//希尔排序(Shell Sort)是插入排序的一种。因D.L.Shell于1959年提出而得名。 #includeusing namespace std;void shell_insert(int num[],int n,int h,int a){ int i,j,temp; for(i=h;i<n;i++) { if(num[i]<num[i-原创 2013-09-05 10:37:52 · 530 阅读 · 0 评论 -
数据结构——冒泡排序
交换排序的基本思想是:两两比较待排序记录的关键字,发现两个记录的次序相反时即进行交换,直到没有反序的记录为止。 应用交换排序基本思想的主要排序方法有:冒泡排序和快速排序。//冒泡排序算法#include using namespace std;void Bubblesort(int num[],int n){ int i,j,temp; for(i=n原创 2013-09-05 10:38:48 · 571 阅读 · 0 评论 -
数据结构——树的孩子表示法
#include using namespace std;#define MAX_TREE_SIZE 100typedef struct Cnode //孩子节点{ char child; struct Cnode * next;}* CNode;typedef struct { char原创 2013-09-04 09:09:00 · 3857 阅读 · 0 评论 -
数据结构——堆排序
#include using namespace std;#define LT(a,b) ( (a) < (b) )#define Listsize 100 //表空间的大小可根据实际需要而定,这里假设为100typedef int DataType; //DataType的类型可根据实际情况而定,这里假设为inttypedef struct原创 2013-09-03 16:44:54 · 573 阅读 · 0 评论 -
数据结构——顺序存储二叉树
#include using namespace std;#define MAX_NODE_SIZE 100 //二叉树的最大节点数typedef char SqBiTree[MAX_NODE_SIZE+1]; //0号单元节点个数//创建二叉树void creat_tree(SqBiTree &t){ int i=0;原创 2013-09-04 09:16:05 · 642 阅读 · 0 评论 -
数据结构——稀疏矩阵
#include using namespace std;#define MTSMXSIZE 12500#define MAXROW 10#define MAXCOL 10typedef int ElemType; typedef struct{ int i,j; //该非零元的行下标和列下标 ElemType e; }Tripl原创 2013-09-04 09:25:30 · 731 阅读 · 0 评论 -
排序法的时间复杂度
一、冒泡排序 1.基本思想: 两两比较待排序数据元素的大小,发现两个数据元素的次序相反时即进行交换,直到没有反序的数据元素为止。 他的名字的由来因为它的工作看来象是冒泡: 复杂度为O(n*n)。当数据为正序,将不会有交换。复杂度为O(0)。 2.排序过程 冒泡排序就是把小的元素往前调或者把大的元素往后调。比较是相邻的两个元素比较,交换也发生在这两原创 2013-09-05 10:23:03 · 507 阅读 · 0 评论 -
数据结构——顺序栈
#include using namespace std;#define StackSize 10 //假定预分配的栈空间最多为100个元素typedef int DataType; //假定栈元素的数据类型为字符typedef struct{ DataType data[StackSize]; int top;}SeqStack;原创 2013-09-05 10:29:54 · 596 阅读 · 0 评论 -
数据结构——单链表的基本操作
#include using namespace std;struct node{ int data; struct node * next;};typedef struct node Node;//创建链表函数Node *Creat(){ Node *h=NULL,*p1,*p2; cout<<"Input intege原创 2013-09-05 10:33:11 · 549 阅读 · 0 评论 -
数据结构——霍夫曼编码解码
#include #include using namespace std;#define MAX 32767 typedef struct{ int weight; char value; int parent; int lchild; int rchild;}HTNode, *HuffmanTree;原创 2013-09-04 09:07:01 · 957 阅读 · 0 评论 -
数据结构——邻接表表示的图的关键路径算法
#include using namespace std;#include #include #define OK 1#define NULL 0#define MAX_VERTEX_NUM 20 // 最大顶点数typedef char VertexType;typedef int VRType;typedef int InforType;ty原创 2013-09-03 16:49:07 · 1360 阅读 · 0 评论 -
数据结构——AVL树的插入
#include using namespace std;#define LH +1 //左高#define EH 0 //等高#define RH -1 //右高#define false 0#define true 1typedef struct BSTNode{ int data; //原创 2013-09-03 16:43:05 · 760 阅读 · 0 评论 -
数据结构——模式匹配
#include using namespace std;#define MaxStrSize 256typedef unsigned char MyString[MaxStrSize+1]; //0号单元存放串的长度/* 掩饰符号类型。例如当需要定义多个包含80个元素的数组a,b,c时,可以这样定义: typedef char Array_e原创 2013-09-04 09:17:35 · 675 阅读 · 0 评论 -
数据结构(3)——二分法查找法
二分法查找(Binary Search)如何从数组里找一个元素的位置?如果排列是无序的,我们只能从头到尾找,但如果排列是有序的,我们则可以用别的更好的方法,二分查找法就类似我们在英汉词典里找一个单词的方法。如下图所示(假如我们要查找的数字是“88”):下面我给出了一段demo代码,来演示二分查找法比顺序查找快多少,代码为了方便起见,初始化有序表的时候填入的数字都是均匀的,而事实上数字可原创 2013-09-02 14:03:54 · 672 阅读 · 0 评论