随笔分类 -  数据结构与算法C++

摘要://大根堆的构建、结点的插入和删除与此完全类似 #include<iostream> using namespace std; class MinHeap { public: int* heap;//存放小根堆中元素的数组 int maxHeapSize;//小根堆最多允许元素个数 int curr 阅读全文
posted @ 2020-07-28 18:07 执着于风 阅读(1254) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; struct BinaryTreeNode{ int ltag,rtag; char data; BinaryTreeNode* leftChild; BinaryTreeNode* rightChild; Binary 阅读全文
posted @ 2020-07-28 18:06 执着于风 阅读(758) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; struct BinaryTreeNode{ char data; BinaryTreeNode* leftChild; BinaryTreeNode* rightChild; BinaryTreeNode(char n 阅读全文
posted @ 2020-07-28 18:03 执着于风 阅读(572) 评论(0) 推荐(0)
摘要:#include<iostream> #define N 100 using namespace std; struct Graph{ int vertex_number; int edge_number; char vertex[N]; int edge[N][N]; }; Graph* G; i 阅读全文
posted @ 2020-07-28 18:02 执着于风 阅读(209) 评论(0) 推荐(0)
摘要:#include<iostream> #include<queue> #include<memory.h> #define maxSize 100 using namespace std; struct edgeNode { int dest; //邻接顶点的数组下标 //int weight; 权 阅读全文
posted @ 2020-07-28 18:00 执着于风 阅读(374) 评论(0) 推荐(0)
摘要:#include <vector> using namespace std; #include<iostream> #include <cstdio> #include <cstring> #define maxn 200005 struct Edge { int v,next; }edge[max 阅读全文
posted @ 2020-07-28 17:59 执着于风 阅读(129) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; void quick_sort(int array[], int start, int end) { if(start>=end) return; //递归终止条件 int i = start; int j = end; 阅读全文
posted @ 2020-07-28 17:57 执着于风 阅读(173) 评论(0) 推荐(0)
摘要:#include<iostream> #include<stdio.h> #define maxn 100 using namespace std; void merge(int arr[],low,mid,high){ int i,j,k; int n1=mid-low+1; int n2=hig 阅读全文
posted @ 2020-07-28 17:56 执着于风 阅读(99) 评论(0) 推荐(0)
摘要:#include<iostream> #include<stdio.h> #include<queue> using namespace std; int main() { priority_queue<int, vector<int>, greater<int> > minHeap; cout<< 阅读全文
posted @ 2020-07-28 17:55 执着于风 阅读(394) 评论(0) 推荐(0)
摘要://vector建图,顶点是数字,本质是邻接表;二维数组建图,顶点是数字,本质是邻接矩阵 #include<iostream> #define maxn 100 //定义一个合适的值作为无边的标志 using namespace std; int main(){ int n,e,w,v1,v2;// 阅读全文
posted @ 2020-07-28 17:54 执着于风 阅读(425) 评论(0) 推荐(0)
摘要:#include<iostream> #include<queue> using namespace std; struct BSTNode{ int data; BSTNode *left,*right; BSTNode(int x,BSTNode* L=NULL,BSTNode* R=NULL) 阅读全文
posted @ 2020-07-28 17:53 执着于风 阅读(84) 评论(0) 推荐(0)
摘要:#include <iostream> #define maxn 1005 using namespace std; int fa[maxn]; void init() { for(int i=1;i<maxn;++i) { fa[i]=i; } } int find_ancestor(int x) 阅读全文
posted @ 2020-07-28 17:51 执着于风 阅读(76) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cmath> using namespace std; int col[10],sum=0; //为了直观,行与列下标都从1开始,范围1-8,col[]数组中存的是每一行皇后位置的列值 void queen(int i){ //i表示当前行 i 阅读全文
posted @ 2020-07-28 17:50 执着于风 阅读(101) 评论(0) 推荐(0)
摘要://vector建图,顶点是数字,本质是邻接表;二维数组建图,顶点是数字,本质是邻接矩阵 #include<iostream> #include<vector> using namespace std; const int N = 100; struct Edge{ int to,value; }e 阅读全文
posted @ 2020-07-28 17:49 执着于风 阅读(384) 评论(0) 推荐(0)
摘要:#include<iostream> #define INF 100 //找一个合适的值作为最大值,表示无边 using namespace std; int n=4; //顶点数 int G[4][4]={ {INF,1,3,5}, {1,INF,2,INF}, {3,2,INF,4}, {5,I 阅读全文
posted @ 2020-07-28 17:48 执着于风 阅读(109) 评论(0) 推荐(0)
摘要:#include<iostream> #include<algorithm> #define maxn 10005 using namespace std; int fa[maxn]; void init(){ for(int i=0;i<maxn;i++){ fa[i]=i; } } int ge 阅读全文
posted @ 2020-07-28 17:47 执着于风 阅读(104) 评论(0) 推荐(0)
摘要:#include <iostream> #include <string> using namespace std; //获取next数组 int* getNext(string T) { int len = T.size(); //获取T的长度 int* next = new int[len]; 阅读全文
posted @ 2020-07-28 17:46 执着于风 阅读(126) 评论(0) 推荐(0)
摘要:#include<iostream> #define INF 10000 //取合适的值作为无穷大表示无边 using namespace std; int n=7; //顶点数 int G[7][7]= { {INF,9,INF,INF,INF,INF,INF}, {9,INF,12,5,INF, 阅读全文
posted @ 2020-07-28 17:44 执着于风 阅读(121) 评论(0) 推荐(0)
摘要:#include<iostream> #include<string> using namespace std; int judge(string S,string T){ int i,j; int s_len=S.size(); int t_len=T.size(); for(i=0;i<=s_l 阅读全文
posted @ 2020-07-28 17:42 执着于风 阅读(100) 评论(0) 推荐(0)
摘要://bf=右子树-左子树,删除时用左子树的中序最后一个结点填充 #include<iostream> #include<stack> #include<queue> using namespace std; struct Node{ int bf; int data; Node* left; Nod 阅读全文
posted @ 2020-07-28 17:41 执着于风 阅读(122) 评论(0) 推荐(0)