- 博客(15)
- 收藏
- 关注
原创 算法导论第十三章 红黑树
文章目录红黑树的定义旋转插入删除习题集合思考题红黑树的定义旋转左旋伪代码LEFT-ROTATE(T,x) 1. y = x.right // 说明x的右孩子为y 2. x.right = y.left // y的左孩子 设为 x的右孩子,即 将β设为x的右孩子 3. if y.left != T.null 4. y.left.p = x 5. y.p = x.p // x的父...
2019-08-11 16:32:46
314
原创 算法导论 第十二章 二叉
二叉搜索树定义:对于任何结点x,其左子树中的关键字最大不超过x.key,其右子树中的关键字最小不小于x.key。而这个性质队树中的每个结点都成立。遍历算法部分:有递归版本有非递归版本分为先序,中序,后序INORDER-TREE-WALK( x ) 1. if x ≠NULL 2. INORDER-TREE-WALK(x ->x.lelf) 3. print x....
2019-08-08 09:01:43
207
原创 算法导论第7,8章快排及线性时间排序
先是第八章 线性时间排序排序算法的下界最坏情况的下界:定理一:在最坏的情况下,任何比较排序算法都需要做下界 为nlgn次比较定理二:堆排序和归并排序都是渐近最优的比较排序算法练习:8.1-1最少进行n-1次比较,所以深度最小是n-18.1-2斯特林近似公式8.1-3key在于n!<=l<=2^h8.1-4计数排序基数排序桶排序...
2019-07-28 10:57:38
157
原创 算法导论-第六章堆排序
假设在第i 次迭代之前,循环不变式为真。那么此时子数组A[1..i] 包含了整个数组A[1..n] 中最小的i个元素,并且A[1..i]是一个最大堆,因此A[1] 保存了子数组A[1..i]中的最大元素,也就是整个数组A[1..n] 中第n−i+1大的元素(有n−i 个元素比它大,所以按从大到小顺序,它是第
2019-07-23 20:26:49
267
原创 ds
#include<bits/stdc++.h>struct a{ int data; struct a*next;};struct a*creakline(){ struct a*H; H=(struct a*)malloc(sizeof(struct a)); H->next=NULL; return H;}void insert(struct a*l)...
2018-12-27 09:26:22
306
转载 反对
#include<iostream>#include<cstring>#include<cstdlib>#define maxn 1000using namespace std;int a[maxn], b[maxn];bool myStrcmp(const char str1[], const char str2[]){ if(strl...
2018-12-27 08:45:43
125
翻译 连通图的DFS,BFS,并查集的试探
自己的DFS,样例没过,果然还是菜#include &lt;iostream&gt;#include&lt;cstdio&gt;#define n 100using namespace std;int v,s;//int flag[n];int DFS(int G[][n],int s ){ int count = 0; int vis[n] = { 0 }; vis[s...
2018-12-14 00:58:29
194
原创 图,dfs,bfs
真的大一菜鸟的dfsdfs:void dfs(int st,int g[][max])//必须给一个顶点开始搜索 { static int vis[max]={0}; //用于记录有没有被访问 vis[st]=1; //开始找说有项链的节点中没有被访问过的节点 printf("%2d->",...
2018-12-12 09:28:46
260
原创 链表学习
突然讲链表,哼 #include<stdio.h> #include<stdlib.h> //定义个链表。 struct NODE{ int order; char name[20]; struct NODE *pnext;//指向truct node的一个指针,链的产生这 }; //创建节点...
2018-12-12 09:02:55
311
1
原创 HDOJ2011多项式求和
不能AC#include <iostream>#include<cstdio>using namespace std;int main(){ int n,flag; while(scanf("%d",&n)!=EOF) { while(n) { flag=1; ...
2018-12-08 22:54:04
147
原创 HDOJ2009
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int main (){ int m; double sum=0,n; while(scanf("%lf%d",&n,&m)!=EOF) { sum=n...
2018-12-07 23:00:56
75
原创 HDOJ2008数值统计
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int main (){ int z,f,zero,n; while(scanf("%d",&n)!=EOF) { if(n==0)break; z=0...
2018-12-07 21:44:09
242
原创 HDOJ2006平方和与立方和
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int main (){ int a,b,t,ou=0,ji=0; while(scanf("%d%d",&a,&b)!=EOF) { ou=0; ...
2018-12-07 21:34:52
260
1
原创 HD2006 求奇数的乘积
#include#includeusing namespace std;int main (){int str=1,n;while(scanf("%d",&n)!=EOF){str=1;for(int i=0;i<n;i++){int s;cin>>s;if(s%2!=0)str*=s;elsecontinue;}cout<<...
2018-12-07 21:24:05
110
原创 HD2003求绝对值
#include#include#includeusing namespace std;int main (){double r;while(cin>>r){ printf("%.2lf\n",fabs(r));}}
2018-12-07 20:31:38
171
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人