算法导论
happy曾帅
这个作者很懒,什么都没留下…
展开
-
C++实现算法导论十五章动态规划之钢条分割问题
#include#include#include#includeusing namespace std;//采用普通的递归算法来求解钢条分割的最大的收益int cut_rod(int *p,const int &n){ if(n==0) return 0; int q=-1; for(int i=1;i<=n;++i) { q=max(q,p[i]+cut_rod(p原创 2014-11-10 14:43:09 · 705 阅读 · 0 评论 -
算法导论学习笔记-第十三章-红黑树
第十三章 红黑树 总结:这章介绍了红黑树的性质、旋转,并详细介绍了红黑树的插入和删除。 1. 红黑树的性质1) 每个节点或是红的,或是黑的2) 根节点是黑的3) 每个叶节点(NIL)是黑的4) 如果一个节点是红的,则它的两个儿子都是黑的5) 对每个节点,从该节点到其子孙节点的所有路径上包含相同数目的黑节点。 黑高度:从某个节点x出发到大一原创 2014-10-31 19:30:27 · 512 阅读 · 0 评论 -
算法导论学习笔记-第十三章-红黑树
算法导论十三中红黑树的插入和删除操作转载 2014-10-31 16:22:31 · 457 阅读 · 0 评论 -
面试宝典中用C++实现循环队列
C++实现循环队列原创 2014-11-04 19:12:21 · 749 阅读 · 0 评论 -
用C++实现顺时针增加的螺旋队列
#includeusing namespace std;int a[10][10];void foo(int n){ int m=1; int i,j; for(i=0;i<n/2;++i) { for(j=0;j<n-i;++j) { if(a[i][j]==0) a[i][j]=m++; } for(j=i+1;j<n-i;++j) {原创 2014-11-04 19:54:27 · 1534 阅读 · 0 评论 -
完整的C++实现算法导论十三章红黑树以及十四章中的顺序统计树
#includeusing namespace std;class BRTree;class BRTreeNode{private: friend class BRTree; int key; bool color; int size; BRTreeNode *left; BRTreeNode *right; BRTreeNode *parent;public: //创原创 2014-11-06 14:14:17 · 887 阅读 · 0 评论 -
算法导论第十五章之钢条切割问题(自顶向下法)
#include#includeusing namespace std;#define inf -9999int memorized_cut_rod_aux(int p[],int n,int r[]){ int q=0; if(r[n]>=0) { return r[n]; } else { //int q=inf; for(int i=1;i<=n;++i)原创 2014-12-15 20:01:49 · 624 阅读 · 0 评论 -
算法导论第十五章之钢条切割问题(自底向上版本)
#includeusing namespace std;int bottom_up_cut_rod(int p[],int n,int &pos){ int *r=new int[n+1]; int *s=new int[n+1]; for(int i=0;i<=n;++i) s[i]=0; for(int i=0;i<=n;++i) r[i]=0; for(int j=1原创 2014-12-15 20:02:59 · 598 阅读 · 0 评论 -
大正数减法(华为2013校园招聘上机笔试题 )
问题描述: 两个任意长度的正数相减,这两个正数可以带小数点,也可以是整数,请输出结果。 输入的字符串中,不会出现除了数字与小数点以外的其它字符,不会出现多个小数点以及小数点在第一个字符的位置等非法情况,所以考生的程序中无须考虑输入的数值字符串非法的情况。 详细要求以及约束:1.输入均为正数,但输出可能为负数; 2.输入输出均为字符串形式;3.如果输出是正数则不需要带符号,原创 2014-12-28 16:18:35 · 686 阅读 · 0 评论 -
算法导论贪心算法之活动选择
活动选择问题的递归调用算法#includeusing namespace std;#define N 11struct node{ int id; int satrt; int end;}A[N+1];void recursive_activity_seclect(int k,int n){ int m=k+1; while(m<=n&&A[m].satrt<A[k].e原创 2014-12-29 10:26:58 · 503 阅读 · 0 评论 -
C++实现判断搜集合法性功能
#include#include#includeusing namespace std;const int length=13;int is_valid(char *input){ if(length==strlen(input)) { if('8'==*input&&'6'==*(input+1)) { while(*input!='\0') { if原创 2015-03-25 09:22:17 · 543 阅读 · 0 评论 -
算法导论中如何求两个字符串的最长公共子序列
#include#includeusing namespace std;const int max_length=10;void print(int b[max_length][max_length],string X,int i,int j);void LCS(string X,string Y,int b[max_length][max_length],int m,int n ){原创 2015-05-08 15:42:34 · 805 阅读 · 0 评论 -
C++抽象数据类型,如何抽象
C++抽象数据类型,如何抽象原创 2014-11-01 21:16:15 · 757 阅读 · 0 评论 -
C++实现在一个字符串中寻找最大子串
C++实现寻找最大的子串原创 2014-10-30 19:21:29 · 2006 阅读 · 0 评论 -
算法导论第二章C++实现归并算法排序
算法导论第二章归并排序算法的C++实现原创 2014-10-30 11:55:33 · 596 阅读 · 0 评论 -
算法导论中十二章C++实现二叉查找树建立,插入,删除,遍历操作
#include #include using namespace std; /*二叉查找树结构*/ typedef struct BSTree { int node_value; struct BSTree * left; struct BSTree * right; struct BSTree * par转载 2014-10-28 22:33:13 · 421 阅读 · 0 评论 -
算法导论中C++实现平衡二叉树(AVL树)
#include #include #include #define EQ(a,b) ((a)==(b))#define LT(a,b) ((a)#define LQ(a,b) ((a)>(b))#define LH +1 //左高#define EH 0 //等高#define RH -1 //右高#define maxSize 20#define max转载 2014-10-29 10:14:44 · 607 阅读 · 0 评论 -
冒泡排序(1)
每次排序使得最小的一个元素在最上面原创 2014-10-29 14:58:30 · 379 阅读 · 0 评论 -
算法导论第十二章关于搜索二叉树的建立,查询,查找最大最小元素值,查找给定结点的直接后继
最近在苦练C++,看到了算法导论中十二章关于搜索二叉树的讲解搜索原创 2014-10-22 22:08:00 · 530 阅读 · 0 评论 -
算法导论第6章实现堆排序的完整程序
#includeusing namespace std;#define parent(i) (i/2)#define left(i) (2*i)#define right(i) (2*i+1)//定义一个交换值的函数void swap(int &a,int &b){ int tmp; tmp=a; a=b; b=tmp;}//下面定义一个维护最大堆的函数void ma原创 2014-10-29 16:44:17 · 445 阅读 · 0 评论 -
关于C++输出流cout的执行顺序问题
首先看一个例子:int fun1(){ cout return 1;}int fun2(){ cout return 2;}int main(){ cout " return 0;} 输出结果是num2num11 2为什么呢?为什么不是num11num22呢?这里涉及到cout原创 2014-10-23 11:47:13 · 1164 阅读 · 0 评论 -
算法导论第七章快速排序的C++实现
这个程序应该比较简单,弄清思路两下就出来了#includeusing namespace std;#define parent(i) (i/2)#define left(i) (2*i)#define right(i) (2*i+1)//定义一个交换值的函数void swap(int &a,int &b){ int tmp; tmp=a; a=b; b=tmp;}原创 2014-10-29 17:19:06 · 360 阅读 · 0 评论 -
C++实现简单的选择排序
#includeusing namespace std;//定义一个交换函数void swap(int &a,int &b){ int tmp; tmp=a; a=b; b=tmp;}void bubblesort(int *A,int length){ int min; int i,j; for(int i=0;i<length-1;++i) { min=i原创 2014-10-29 15:31:26 · 406 阅读 · 0 评论 -
简单插入排序
C++实现简单的插入排序原创 2014-10-29 21:05:59 · 553 阅读 · 0 评论 -
数据结构中用C++实现平衡二叉搜索树
#ifndef _AVL_H_#define _AVL_H_#include #define LH 1 //左高#define EH 0 //等高#define RH -1 //右高//平衡二叉排序树结点结构 template struct AVLNode{ ElemType data; //结点数据域 AVLNode *lchild;转载 2014-10-29 21:57:44 · 521 阅读 · 0 评论 -
算法导论第二章C++实现归并排序
归并排序的思想算法导论里面讲的很详细的,,但数学原创 2014-10-30 11:14:29 · 403 阅读 · 0 评论 -
如何做好一个合格程序员
从框架上分析代码,不要眼高手低,认真阅读代码的每一行,不懂的就一直专研或者问同事,不要自我觉得懂了明白了,绕过去,最后发现欺骗的还是你自己原创 2017-08-15 14:34:15 · 626 阅读 · 0 评论