数据结构
数据结构
weixin_39518639
这个作者很懒,什么都没留下…
展开
-
数据结构-文件处理
文件载入内存,生成链表实现查询,删除,修改student1.txt182544,陆一在,18911555661193752,孙训兰,18911555662197132,程昕,18911555663205844,王亚威,18911555664bdfunction.h#pragma once#include <stdio.h>#include<stdlib.h>#include"memfunction.h"//内存管理函数的头文件//定义链表结构(指针链表void原创 2020-11-26 13:50:51 · 209 阅读 · 0 评论 -
数据结构-排序-归并排序
#include<stdio.h>#include<stdlib.h>// 16 17 13 10 9 15 3 2 5 8 12 1 11 4 6 14void Merge(int * arr1, int * arr2, int head, int middle, int tail){ int t = middle+1; //int k=0;//arr2的坐标 此处的k不能为0,为0的话会覆盖之前已经比较过的 int k = head; for (; head.原创 2020-09-13 17:01:34 · 57 阅读 · 0 评论 -
数据结构-排序-shellsort希尔排序
#include<stdio.h>#include<stdlib.h>void show(int *arr,int sum){ for (int i = 0; i < sum; i++) printf("%d,", arr[i]); printf("\n");}//希尔排序void shellSorta(int * arr, int sum)//在插入排序的基础上增加一个增量,将增量的记录组成一个子序,再进行排序/*arr[10] = { 0,9,.原创 2020-08-25 18:01:20 · 123 阅读 · 0 评论 -
数据结构-排序-冒泡排序-快速排序-插入排序-堆排序
#include<stdio.h>#include<stdlib.h>void swap(int *a, int *b){ int temp = *a; *a = *b; *b = temp;}void show(int *arr,int sum){ for (int i = 0; i < sum; i++) printf("%d,", arr[i]); printf("\n");}void maopao(int *arr,int su.原创 2020-08-24 15:34:26 · 157 阅读 · 0 评论 -
数据结构-迷宫(采用迪杰斯算法)最短路径走出迷宫
main.cpp#include <stdio.h>#include <stdlib.h>#include "function.h"void main(){ int maze[ROW][COL] = { 0 }; InitMaze(maze);//初始化迷宫 DrawMaze(maze);//绘制迷宫 AImazeDijkistra(maze);//AI算法最短路径 system("pause");}function.h#include<s原创 2020-08-18 14:31:22 · 1304 阅读 · 2 评论 -
数据结构-迷宫
迷宫.cpp#include <stdio.h>#include <stdlib.h>#include "function.h"void main(){ int maze[10][10] = {0}; InitMaze(maze); DrawMaze(maze); AImaze(maze,0,0); if (maze[9][9] != 1) printf("此路不通\n"); else printf("走出来了\n"); //ControlMaz原创 2020-08-14 13:56:53 · 139 阅读 · 0 评论 -
数据结构-排序-平衡二叉排序树
双旋转的平衡因子的处理BalanceLiftRotate()函数1、先判断10的BL为-1,说明新增节点9在右边,这时直接左旋就可以如果10的BL为+1,说明新增节点9在左边,这时如果直接左旋,就不符合排序二叉树左小右大的规则,这时要进行双旋转操作。双旋之前要先重新处理平衡因子(BL)2、根据9的平衡因子,处理7,10节点的平衡因子如果9的平衡因子为0,则7,10的平衡因子设为0;如果9的平衡因子为1,则7的平衡因子为-1,10的平衡因子为0;如果9的平衡因子为-1,则7的平衡因子为0,10.原创 2020-08-06 11:41:14 · 289 阅读 · 0 评论 -
数据结构-查找-二分查找-插值查找-斐波那契查找
二分查找:对半比较,再对半比较,直到找到或找不到;插值查找:二分查找法的升级,根据查找的内容算出比率,取代二分之一。(效率最高)斐波那契查找:也是二分查找法为基础,但是比率是按斐波那契数列进行的。main.cpp#include<iostream>#include<stdio.h>#include <stdlib.h>#include<string>#include"structfun.h"using std::string;using原创 2020-07-31 09:57:47 · 124 阅读 · 0 评论 -
数据结构-图-有向无环图-关键路径查找
拓扑排序:0,2,5,1,3,4,6,7,8,9etv:顶点的最早发生时间ltv:顶点的最晚发生时间节点的etv=ltv,就是图的关键路径;1、计算etv[0-9] etv[0]的值为0;etv[2]的值为4;etv[5]的值为4+7=11;etv[1]的值为3;etv[3]的值为3+5=8与4+8=12之间选择,选择最大的为12;etv[4]的值为3+6=9与12+3=15之间选择,选择最大的为15;etv[6]的值为15+9=24;etv[7]的值为15+4=19与11+6=17之间选择,.原创 2020-07-27 16:13:31 · 304 阅读 · 0 评论 -
数据结构-图-拓扑排序算法
方法:采用邻接表数据结构,加入顶点入度in,定义一个栈,用于存储入度为零的顶点1、循环查找首次入度为零的顶点,入栈2、循环,出栈,打印栈顶,处理栈顶指向顶点的入度减一,减一后入度为零的顶点再入栈,直到栈为空推出循环。main.cpp#include<iostream>#include<stdio.h>#include <stdlib.h>#include<string>#include"structfun.h"using std::str原创 2020-07-24 11:49:18 · 389 阅读 · 0 评论 -
数据结构-图-最短路径-弗洛伊德算法(Floyd)
1.txtv0v1v2v3v4v5v6v7v80,1,10,2,51,2,31,3,71,4,52,4,12,5,73,4,23,6,34,5,34,6,64,7,95,7,56,7,26,8,77,8,40,0,0structfun.h//数据结构函数头文件#include <stdio.h>#include <iostream>#include<string>using std::cout;u..原创 2020-07-17 17:15:33 · 333 阅读 · 0 评论 -
数据结构-图-最短路径-迪杰斯特拉算法(Dijkistra)
分析:D数组存权重集合,F存访问标识,P存顶点,m最小权重,cur记录m的顶点。D【0,1,5,-,-,-,-,-,-】F【1,0,0,0,0,0,0,0,0】P【0,0,0,0,0,0,0,0,0】 m=1 cur=1在v0->v1最短路径的基础上,计算v1到其他相连的顶点,f[n]!=1的边;D【0,1,54 ,8,6,-,-,-,-】F【1,1,0,0,0,0,0,0,0】P【0,0,1,1,1,0,0,0,0】 m=4 cur=2在v0->v2最短路径的基础上,计算v..原创 2020-07-16 15:42:06 · 301 阅读 · 0 评论 -
数据结构-图-最小生成树-克鲁斯卡尔算法(Kruskal)边多的用prim,边少的用kruskal
思路:设置一个数组p[edgenum],存放访问过的边,设置一个边集数组结构,存放边的begin,end,weight.把所有边放入边集数组,并按权重从小到大排序。n为p的下标 m为p的值1:权重 7 输出 h e(7 4) 数组p(000070000) n=4 m=72:权重8 输出 i c (8 2) p(008070000) n=2 m=83:权重10输出 ba (1 0) p(108070000) n=0 m=14:权重11输出 fa ..原创 2020-07-07 15:04:25 · 176 阅读 · 0 评论 -
数据结构-图-最小生成路径-prim算法
思路:一、从A开始 A->B 10,A->F 11 输出A->B;二、A->F 11 ,B->F18 , B->I 12 ,B->G16 输出A->F;三、BC 18 BI 12 BG 16 FG 17 FE 26 输出BI 12;四、BC 18 BG 16 FG 17 FE 26 IC 8 ID 21输出IC 8;五、BC 18 BG 16 FG 17 FE 26 ID 21 CD 22 输出BG16;六、FE26 ID 21 CD 22 ..原创 2020-07-06 14:10:57 · 214 阅读 · 0 评论 -
数据结构-图的深度遍历和广度遍历-邻接矩阵-邻接表
structfun.h//数据结构函数头文件#include <stdio.h>#include <iostream>#include<string>using std::cout;using std::cin;using std::string;#define MAXSIZE 100#define OK 1#define ERROR 0#define INFINITY 65535//无穷大typedef string ElemType;.原创 2020-07-02 09:53:49 · 907 阅读 · 0 评论 -
数据结构-图的4种结构-邻接矩阵-邻接表-十字链表-邻接多重链表
边节点数据结构:iver,ilink,jver,jlink创建边节点时,查找iver,jver对应下标开始最后ilink,jlink为空时,把ilink或jlink指向当前所创建的节点。顶点的edgefrist指针为空时表示创建的边节点为该顶点的第一条边。edgefirst直接指向该节点。structfun.h//数据结构函数头文件#include <stdio.h>#include <iostream>#include<string>using s.原创 2020-06-25 15:13:05 · 304 阅读 · 0 评论 -
数据结构-树-哈夫曼树-哈夫曼编码
structfun.h//数据结构函数头文件#include <stdio.h>#include <iostream>#include<string>using std::cout;using std::cin;using std::string;#define MAXSIZE 200#define OK 1#define ERROR 0typedef string ElemType;//4->二叉链表存储结构(二叉链表存储结构跟树原创 2020-06-21 17:51:45 · 178 阅读 · 0 评论 -
数据结构-树-二叉链表-前序遍历-中序遍历-后序遍历
structfun.h//数据结构函数头文件#include <stdio.h>#include <iostream>#include<string>using std::cout;using std::cin;using std::string;#define MAXSIZE 200#define OK 1#define ERROR 0typedef string ElemType;//二叉链表存储结构(二叉链表存储结构跟树的孩子兄弟表原创 2020-06-19 14:05:13 · 606 阅读 · 0 评论 -
数据结构-单链表
#include <stdio.h>#include <iostream>using namespace std;typedef char ElemType;//定义单链表数据结构typedef struct Node{ ElemType data; struct Node *next;}Node;typedef struct Node *LinkList;//初始化链表LinkList InitList(){ //函数功能:初始化链表L /原创 2020-05-25 17:11:32 · 88 阅读 · 0 评论 -
数据结构静态链表
//静态链表是用数组的方式实现链表的数据结构#include <stdio.h>#include <iostream>using namespace std;#define MAXSIZE 1000#define OK 1#define ERROR 0typedef char ElemType;typedef int Status; typedef struct { ElemType data; int cur; }StaticLinkList[M原创 2020-05-25 17:15:57 · 130 阅读 · 0 评论 -
循环链表
#include <stdio.h>#include <iostream>using namespace std;typedef char Elemtype;typedef struct Node{ Elemtype data; Node *next;}Node,LinkList;LinkList * InitList(){ //初始化循环链表 Node *head; head=(LinkList *)malloc(sizeof(LinkList))原创 2020-05-26 14:37:38 · 64 阅读 · 0 评论 -
循环双向链表
#include<stdio.h>#include<iostream>using namespace std;typedef char Elemtype;typedef struct DbNode{ Elemtype data; DbNode *prior,*next;}DBLinklist;//创建空双向循环链表DBLinklist *InitList(){ DbNode *head; head=(DBLinklist*)malloc(sizeof原创 2020-05-26 16:49:26 · 93 阅读 · 0 评论 -
栈-四则运算二(改)
#include<stdio.h>#include<iostream>#include<string>using namespace std;#define STACK_SIZE 100typedef char Elemtype;//定义栈结构typedef struct stack{ Elemtype data[STACK_SIZE]; int top;}stackList;//初始化栈int InitStack(stackList *原创 2020-05-28 17:22:33 · 127 阅读 · 0 评论 -
字符串KMP模式匹配算法
//KMP模式匹配算法//1、定义两个字符数组S1(主串),S2(查找子串)//2、求出S2的next数值//3、根据next数值匹配S1主串#define MAXSIZE 100char S1[MAXSIZE];char S2[MAXSIZE];int next[MAXSIZE];printf("输入主串S1:");cin>>S1;printf("输入子串S2:");cin>>S2;//求S2的next值 //例:S2=abdabg // nex原创 2020-06-05 17:08:46 · 115 阅读 · 0 评论 -
数据结构-树的三种表示法
structfun.h 头文件//树结构定义//1->(双亲表示法)--(数组)typedef struct PtNode//节点结构{ ElemType data; int parent,firstchild,rightsib;//双亲,长子,右兄弟}PtNode;typedef struct{ PtNode nodes[MAXSIZE]; int r,n;//r:根的位置 n结点数}PTree;//2->(双亲孩子表示法)数组+单链表//孩子节点用单链表存储,头指原创 2020-06-12 17:04:11 · 1304 阅读 · 0 评论 -
数据结构-树的前序-中序-后序线索化及遍历
structfun.h//数据结构函数头文件#include <stdio.h>#include <iostream>#include<string>using std::cout;using std::cin;using std::string;#define MAXSIZE 200#define OK 1#define ERROR 0typedef string ElemType;//5->线索二叉树存储结构typedef e原创 2020-06-19 13:46:22 · 163 阅读 · 0 评论