Sort a linked list in O(n log n) time using constant space complexity.一谈到时间复杂度O(nlogn),立即联想到以下3种排序方法:1.归并排序(基于分治):时间复杂度O(nlogn),归并排序的最好、平均、最坏时间复杂度没有差别... Read More
posted @ 2014-06-08 23:14 Xylophone Views(228) Comments(0) Diggs(0)
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.思路:(1)点1到点n (a)以点1为参考点,求“点1”与“点2到点n”各个斜率下点的个数; (求出直... Read More
posted @ 2014-06-07 23:28 Xylophone Views(183) Comments(0) Diggs(0)
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another ex... Read More
posted @ 2014-06-07 09:36 Xylophone Views(194) Comments(0) Diggs(0)
Reverse Words in a StringGiven an input string, reverse the string word by word.For example, Given s = "the sky is blue", return "blue is sky the".Cla... Read More
posted @ 2014-06-05 18:59 Xylophone Views(177) Comments(0) Diggs(0)
题目:n个人编号分别是1,2,3,...,n,围坐在一张圆桌周围,从编号为k的人开始报数,数到m的人出列。然后他的下一个人开始报数,数到m的那个人又出列;依次循环,直到所有人出列。struct LNode{ int data; LNode *next;};//n为总人数,k为第一个开始报数的人,... Read More
posted @ 2014-05-05 09:59 Xylophone Views(552) Comments(1) Diggs(0)
struct BiTreeNode{ int data; BiTreeNode *leftChild; BiTreeNode *rightChild;};三种遍历是:前序、中序、后序遍历;每种遍历的实现都有递归和循环2种方法。(注:递归在本质上就是一个栈结构,所以遍历的循环方法可以用栈实现)前序遍历... Read More
posted @ 2014-04-25 10:49 Xylophone Views(377) Comments(0) Diggs(0)
1.预处理 预处理器是在真正的编译开始之前由编译器调用的独立程序。预处理器可以删除注释、包含其他文件以及执行宏替代。 预处理命令(宏定义#define..#undef、 文件包含#include、 条件编译#ifndef...(#else)...#endif 或者 #if...(#else)..#endif)不是C++语句(以“#”开头,末尾不包含分号),不能直接编译。 宏的优缺点说明: 1). 首先谈一下在C中使用这种形式宏定义的原因,C语言是一个效率很高的语言,这种宏定义在形式及使用上像一个函 数,但它使用预处理器实现,没有参数压栈,代码生成等一系列的操作,因此,效率很高,这是它在C中被. Read More
posted @ 2014-03-30 13:14 Xylophone Views(894) Comments(0) Diggs(0)
strcpy 函数的原型是: char * strcpy(char * strDest,const char * strSrc); 功能:把从strSrc地址开始且含有NULL结束符的字符串复制到以strDest开始的地址空间,返回指向strDest的指针。说明:strSrc和strDest所指内存区域不可以重叠且strDest必须有足够的空间来容纳strSrc的字符串。 与strncpy 函数进行对比:strncpy 函数的原型是: char * strncpy( char *dest, char *src, size_t num ); 下面的例子可以看出strcpy和strncpy的区别: Read More
posted @ 2014-03-27 11:40 Xylophone Views(445) Comments(0) Diggs(0)
写这篇博客的缘由: 对于专利《基于边缘自适应的高效图像盲去模糊方法》,是关于图像处理方面的,平时写代码和分析问题时一套一套的,很长时间不讲突然要向别人说就磕磕巴巴的也说不清楚。遂有了要认真思考,并陈述总结自己所学的想法。虽然以后并不定做盲去模糊方面的东西,但所学总有相通。遂写下这篇文章描述整体思路。 Read More
posted @ 2014-03-24 17:46 Xylophone Views(3302) Comments(0) Diggs(0)
1.首先cin>>a返回的是左操作数,也就是返回cin。cin的条件状态中: cin.eof() 判断流是否到达文件的结束符 cin.fail() 判断IO操作是否失败在while(cin>>a)中看流是否还能用,主要是判断 cin.fail()的取值。事实上,无论是否用于while循环,流必须处于无错误状态才能用于输入和输出,也就是cin.fail()必须为0值,程序以下的cin操作才能正常执行。导致cin.fail()为1的操作有:输入坏值 或 遇到文件结束符(ctrl+z)当cin.fail()=1时,可以设置cin.clear()将流中的所有状态值设为有效状态, Read More
posted @ 2013-12-03 22:11 Xylophone Views(1723) Comments(0) Diggs(0)