![](https://img-blog.csdnimg.cn/20190918140158853.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
数据结构
考研路上数据结构相关的知识点
小飞猪Jay
远风知我意,微凉又深情。
展开
-
最小生成树Prim,Kruskal和单源最短路径Dijkstra
Prim:#include <iostream>#include <malloc.h>#define maxSize 20 #define INF 6000 using namespace std;char VName[5]={'A','B','C','D','E'};int weight[5][5]={0,3,2,4,1,3,0,5,INF,6,2,5,0,2,INF,4,INF,2,0,INF,1,6,INF,INF,0};typedef struct VNo原创 2021-12-21 19:33:56 · 118 阅读 · 0 评论 -
用DFS,BFS判断图中点i和点j是否连通
#include <iostream>#include <malloc.h>#define maxSize 20 using namespace std;char VName[5]={'A','B','C','D','E'};typedef struct ArcNode{ int adjvex; struct ArcNode *next;}ArcNode;typedef struct VNode{ char data; ArcNode *first;}V原创 2021-12-21 19:20:52 · 84 阅读 · 0 评论 -
判断无向图是否为一棵树
#include <iostream>#include <malloc.h>#define maxSize 20 using namespace std;char VName[5]={'A','B','C','D','E'};typedef struct ArcNode{ int adjvex; struct ArcNode *next;}ArcNode;typedef struct VNode{ char data; ArcNode *first;}V原创 2021-12-21 19:14:01 · 172 阅读 · 0 评论 -
求不带权连通图中距点v的最远点
用dfs来实现的#include <iostream>#include <malloc.h>#define maxSize 20 using namespace std;char VName[5]={'A','B','C','D','E'};typedef struct ArcNode{ int adjvex; struct ArcNode *next;}ArcNode;typedef struct VNode{ char data; ArcNode *原创 2021-12-21 19:06:21 · 152 阅读 · 0 评论 -
图的DFS深度优先搜索
#include <iostream>#include <malloc.h>#define maxSize 20 using namespace std;char VName[5]={'A','B','C','D','E'};typedef struct ArcNode{ int adjvex; struct ArcNode *next;}ArcNode;typedef struct VNode{ char data; ArcNode *first;}V原创 2021-12-21 18:52:32 · 54 阅读 · 0 评论 -
图的BFS广度优先搜索
#include <iostream>#include <malloc.h>#define maxSize 20 using namespace std;char VName[5]={'A','B','C','D','E'};typedef struct ArcNode{ int adjvex; struct ArcNode *next;}ArcNode;typedef struct VNode{ char data; ArcNode *first;}V原创 2021-12-20 18:41:00 · 194 阅读 · 0 评论 -
图邻接表的定义
#include<bits/stdc++.h>#define maxSize 20using namespace std;char VName[5]={'A','B','C','D','E'};int weight[5][5]={0,3,2,4,1,3,0,5,0,6,2,5,0,2,0,4,0,2,0,0,1,6,0,0,0};typedef struct VNode{ int no; //点的编号 char data; //点的字母 }VNode;ty原创 2021-12-20 18:34:20 · 296 阅读 · 0 评论 -
输出二叉树根节点到每个叶结点的路径
#include<bits/stdc++.h>using namespace std;typedef struct BTnode{ int data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h,*i; T = (BTnode*)malloc(sizeof(BTnode));T->原创 2021-12-20 17:02:21 · 502 阅读 · 0 评论 -
中序线索二叉树的创建和遍历
#include<bits/stdc++.h>#define maxSize 20using namespace std;typedef struct BTnode{ int data; int ltag , rtag; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h,*i; T =原创 2021-12-20 16:43:03 · 232 阅读 · 0 评论 -
查找二叉树前序中序后序遍历的第n个值
#include<bits/stdc++.h>#define maxSize 20using namespace std;typedef struct BTnode{ char data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h; T = (BTnode*)malloc(size原创 2021-12-20 16:30:51 · 436 阅读 · 0 评论 -
查找二叉树中的关键值key
#include<bits/stdc++.h>using namespace std;typedef struct BTnode{ char data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h; T = (BTnode*)malloc(sizeof(BTnode));T->d原创 2021-12-20 16:25:06 · 787 阅读 · 0 评论 -
求二叉树的深度
#include<bits/stdc++.h>#define maxSize 20using namespace std;typedef struct BTnode{ int data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;typedef struct St{ BTnode *p; int l;}St;void createTree(BTnode *&T){ BTnode *a,*b,*c原创 2021-12-20 16:13:31 · 68 阅读 · 0 评论 -
表达树求值
#include<bits/stdc++.h>using namespace std;typedef struct BTnode{ char data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h; T = (BTnode*)malloc(sizeof(BTnode));T->d原创 2021-12-19 20:44:37 · 70 阅读 · 0 评论 -
二叉树的层次遍历
#include<bits/stdc++.h>#define maxSize 20using namespace std;typedef struct BTnode{ int data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h,*i; T = (BTnode*)malloc(si原创 2021-12-19 20:22:37 · 64 阅读 · 0 评论 -
二叉树的前中后序非递归遍历
#include<bits/stdc++.h>#define maxSize 50using namespace std;typedef struct BTnode{ int data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h,*i; T = (BTnode*)malloc(si原创 2021-12-19 20:14:49 · 184 阅读 · 0 评论 -
二叉树的前中后序遍历
#include<bits/stdc++.h>using namespace std;typedef struct BTnode{ int data; struct BTnode *lchild; struct BTnode *rchild;}BTnode;void createTree(BTnode *&T){ BTnode *a,*b,*c,*d,*e,*f,*g,*h,*i; T = (BTnode*)malloc(sizeof(BTnode));T->原创 2021-12-19 20:12:01 · 193 阅读 · 0 评论 -
将数组内的所有奇数放到偶数前
#include<bits/stdc++.h>using namespace std;int a[10] = {2,4,1,3,5,6,7,8,9,10};void solve(int a[] , int n){ int low = 0; int temp = 0; int flag = 0; for(int i = 0 ; i < n ; i++) { if(a[i]%2!=0) { if(flag == 0) { low++; }原创 2021-12-19 20:05:59 · 258 阅读 · 0 评论 -
递归求数组的最大值、数组和、平均值
#include<bits/stdc++.h>using namespace std;int a[10] = {1,3,13,345,21,34,54,6645,0,6};int k = -1;int sum = 0;int ave = 0;void get_max(int a[] , int n){ if(n == 10) cout << "最大值为:" << k << endl; else { if(k<a[n]) {原创 2021-12-19 20:03:51 · 281 阅读 · 0 评论 -
链队的入队和出队操作
#include<bits/stdc++.h>using namespace std;typedef struct node{ int data; struct node *next;}Linknode;typedef struct{ Linknode *front , *rear;}LinkQueue;void InitQueue(LinkQueue *Q){ Q->front = Q->rear = (Linknode*)malloc(sizeof(Li原创 2021-12-19 19:57:17 · 282 阅读 · 0 评论 -
计算后缀表达式
#include<bits/stdc++.h>using namespace std;char A[10] = {'1','2','3','4','*','+','+','3','/','\0'};int op(int x , int y , char z){ if(z=='+') return x+y; if(z=='-') return x-y; if(z=='*') return x*y; if(z=='/') { if(y==0) { printf("分母原创 2021-12-19 19:55:50 · 70 阅读 · 0 评论 -
判断表达式中的括号匹配(顺序栈/链栈)
顺序栈实现:#include<bits/stdc++.h>using namespace std;char A[10] = {'(','[','(','(',']',')',']',')'};void match(char A[] , int n){ char stack[10]; int top = -1; for(int i = 0 ; i < n ;i++) { if(top == -1 || A[i]=='('||A[i]=='[') { top+原创 2021-12-19 19:50:48 · 152 阅读 · 0 评论 -
链栈的出栈和入栈操作
#include<bits/stdc++.h>using namespace std;typedef struct node{ int data; struct node *next;}LinkStack;LinkStack* push(LinkStack *s , int x){ LinkStack *h = (LinkStack*)malloc(sizeof(LinkStack)); h->data = x; h->next = s; s = h; ret原创 2021-12-19 19:45:17 · 499 阅读 · 0 评论 -
将两升序单链表A和B求差集存入A中
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}LinkNode;LinkNode* Creat_LinkList2(){ int x; LinkNode* h; LinkNode *s,*t; printf("请输入链表的数据域的值,-1表述输入结束:"); scanf("%d",&x)原创 2021-12-17 21:14:09 · 135 阅读 · 0 评论 -
将链表中第i到第j个元素逆置
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}LinkNode;LinkNode* Creat_LinkList2(){ int x; LinkNode* h; LinkNode *s,*t; printf("请输入链表的数据域的值,-1表示输入结束:"); scanf("%d",&x)原创 2021-12-17 21:12:24 · 214 阅读 · 0 评论 -
头插法建链表
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}LinkNode;LinkNode* Creat_LinkList2(){ int x; LinkNode* h; LinkNode *s,*t; printf("请输入链表的数据域的值,-1表述输入结束:"); scanf("%d",&x)原创 2021-12-17 21:08:33 · 269 阅读 · 0 评论 -
尾插法建链表
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}LinkNode;LinkNode* Creat_LinkList2(){ int x; LinkNode* h; LinkNode *s,*t; printf("请输入链表的数据域的值,-1表示输入结束:"); scanf("%d",&x)原创 2021-12-17 21:07:40 · 183 阅读 · 0 评论 -
归并两升序单链表为降序单链表
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}LinkNode;LinkNode* Creat_LinkList2(){ int x; LinkNode* h; LinkNode *s,*t; printf("请输入链表的数据域的值,-1表示输入结束:"); scanf("%d",&x)原创 2021-12-17 21:06:29 · 865 阅读 · 0 评论 -
合并两升序单链表为升序单链表
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}LinkNode;LinkNode* Creat_LinkList2(){ int x; LinkNode* h; LinkNode *s,*t; printf("请输入链表的数据域的值"); scanf("%d",&x); h=(L原创 2021-12-17 21:02:30 · 367 阅读 · 0 评论