数据结构
cqggcqggcqggcqgg
这个作者很懒,什么都没留下…
展开
-
二叉排序树的递归与非递归建立 C++实现
#include <iostream>using namespace std;typedef struct Node{ int data; struct Node*lchild; struct Node*rchild; struct Node*par; }*BST;//递归建立二叉排序树 int Res_Creat(BST &root, int key){ if(root == NULL) { root = new Node; root->d.原创 2020-12-11 11:26:47 · 162 阅读 · 0 评论 -
Prim算法求解最小生成树 c++代码实现
#include <iostream>#include <algorithm>using namespace std;const int maxn = 100;const int inf = 0x3f3f3f3f;int n, m, sum = 0;int graph[maxn][maxn];bool visit[maxn];int closest[maxn];int lowcost[maxn];void Prim(){ visit[1] = true原创 2020-12-11 09:52:57 · 193 阅读 · 0 评论 -
弗洛伊德算法(floyd)算法求解任意两点之间最短路径问题
#include <bits/stdc++.h>using namespace std;const int maxn = 100;const int inf = 0x3f3f3f3f;int n, m, s, d;int graph[maxn][maxn];int dis[maxn][maxn];void floyd(){ for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dis[i][j]原创 2020-12-11 09:13:47 · 648 阅读 · 0 评论 -
已知二叉树的两种遍历序列,求出另一种遍历序列(详解)
转载地址:http://blog.csdn.net/peiyao456/article/details/52667057已知先序遍历序列和中序遍历序列,求出后序序列 或者 已知中序序列和后序序列 ,求出先序遍历。。都是一些考试中容易考的题目。经过研究发现,已知先序序列和后序序列,无法唯一确定一棵树,所以就无法得知中序序列。下边给出例题:一、已知先序和中序,求出后序。下边再举一个例子,如下图:通过上边两个例子的学习,对这种题目有了一定的理解,下边举例已知中序和后序,求先序。二、原创 2020-10-11 16:24:48 · 2741 阅读 · 0 评论 -
【数据结构】单链队列——队列的链式存储结构
单链队列的基本操作#include <stdio.h>#include <stdlib.h>#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define INFEASIBLE -1#define OVERFLOW -2typedef int QElemType;typedef int Status;//定义队列typedef struct QNode{ QElemType data;原创 2020-09-17 09:53:40 · 281 阅读 · 0 评论 -
【数据结构】栈的基本操作(以顺序栈为例)
对栈的基本操作(顺序栈)1、栈的定义#include <stdio.h>#include <stdlib.h>#include <math.h>#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2#define STACK_INIT_SIZE 100 //栈存储空间的初始分配量#define STACKIN原创 2020-09-17 08:38:48 · 401 阅读 · 0 评论 -
【数据结构】迪杰斯特拉(dijkstra)算法求解单源最短路径问题
问题:迪杰斯特拉算法求解单源最短路径#include <iostream>#include <algorithm>using namespace std;const int inf = 9999;const int maxn = 510;int n, m, s, d;int graph[maxn][maxn];int dis[maxn];int visited[maxn];void dijkstra(){ dis[s] = 0; for(int i =原创 2020-11-19 22:27:33 · 190 阅读 · 0 评论 -
【数据结构】二叉排序树
#include <iostream>#include <cstdlib>using namespace std;typedef struct node{ int key; struct node* lchild; struct node* rchild; struct node* par;}*bst;//递归插入int Creat(bst& root, int key){ if(root == NULL) { root = new node原创 2020-11-03 14:57:18 · 94 阅读 · 0 评论 -
【数据结构】二叉树已知先序和中序遍历求后序遍历
#include <iostream>using namespace std;typedef struct node{ struct node* left; struct node* right; int data;}*bintree;bintree creatbintree(int n, int h[], int in[]){ if(n <= 0) return NULL; bintree tree; tree = new node; tree->d原创 2020-10-13 19:38:22 · 497 阅读 · 0 评论 -
【数据结构】二叉树已知中序和后序遍历求先序遍历
#include <iostream>using namespace std;typedef struct node{ struct node* left; struct node* right; int data;}*bintree;bintree creatbintree(int n, int r[], int in[]){ if(n <= 0) return NULL; bintree tree; tree = new node; tree->dat原创 2020-10-13 19:35:50 · 584 阅读 · 0 评论 -
【数据结构】二叉树的非递归遍历
typedef struct TNode{ struct TNode* left; struct TNode* right; int data;}*BinTree; 1、先序遍历前序遍历按照“根结点-左孩子-右孩子”的顺序进行遍历。具体算法:先遍历左孩子,并输出。当左孩子遍历完后,取栈顶,并借助栈顶找到右孩子。此时循环还没有结束,再遍历它的左子树,右孩子直至孩子全部遍历结束。void PreorderTraversal(BinTree T) //前序遍历 { if(!T) ret原创 2020-10-13 17:02:21 · 265 阅读 · 0 评论 -
【数据结构】迪杰斯特拉(dijkstra)算法 单源最短路径(源点到其它点的最短距离)
#include <iostream>#include <cstring>#define maxn 500#define INF 0x3f3f3f3fusing namespace std;int graph[maxn][maxn]; //尽量定义全局变量int vis[maxn]; //存已查找的顶点int dis[maxn]; //各顶点到源点距离int n, m; //顶点数、边数void dijkstra(int原创 2020-10-06 17:19:46 · 834 阅读 · 0 评论 -
PTA 7-1 删除字符串中的子串 (20分)
#include <iostream>#include <string>using namespace std;int main(){ string s1, s2; getline(cin, s1); getline(cin, s2); int index = s1.find(s2); while(index >= 0) { s1.erase(index, s2.length()); i原创 2020-09-28 17:52:40 · 993 阅读 · 0 评论