2013年3月14日

Effective C++读书笔记

摘要: Scott Meyers是C++写作方面的大牛,effective c++这本书也算是业界知名,重读笔记之。区分declaration and definition. Declaration的目的是告诉编译器声明的标识符的类型。比如extern int bar; double f(int, double); 而definition是declaration的具体实现,linker需要把definition的实现链接到它的引用。通常情况下C++要去所有的变量都需要先declare再提供definition,然后才能使用。唯一的例外是声明在class中的static int/char/bool 类型 阅读全文

posted @ 2013-03-14 00:48 梁霄 阅读(162) 评论(0) 推荐(0)

2013年2月15日

C++ 中的primitive type/fundamental type/conversion

摘要: 前两天在面试的时候其中遇到一个小问题:需要比较一个字符串str_value (value = "10") 和unsigned int int_value 10, 当时没细想就随手写了一个str_value == int_value.str(),对面指出unsigned int并不包含str()方法应该是过不了编译。 后来干脆从另一个方便用atoi把c style的字符串转化成int再和int_value比较 (atoi(str_value.c_str()) == int_value。和java中Interger类都有parse()的方法不同,C++中fundamental 阅读全文

posted @ 2013-02-15 09:50 梁霄 阅读(394) 评论(0) 推荐(0)

2013年2月12日

数据结构和算法的基本知识点复习

摘要: 树的不同类型,full tree是所有非叶结点都有左右两个子节点,complete tree是类似于将结点按层序排列起来的树,perfect tree是在full tree的基础上每一层的结点都填满。AVL树是一种特殊的BST,其特点是对于每一个结点,其左子树的高度和右子树最多相差为1。关于ALV保持如何保持平衡的问题,根据情况氛围single rotation或是double rotation,细节见(http://www.cs.washington.edu/education/courses/cse373/12wi/lectures/cse373-12wi-lec07-AVLTrees-d 阅读全文

posted @ 2013-02-12 00:53 梁霄 阅读(420) 评论(0) 推荐(0)

2013年2月10日

动态规划

摘要: 动态规划的本质就是把一个大问题分解为若干个小问题来解决,知道被分解的最小问题是可以被解决的。常见的动态规划解法包括递归或者使用数组来存储中间计算状态然后通过循环解决。a. 有一个map将ABCDE...Z映射到1234...26. 因此,'26'既可以对应到Z又可以对应到BF,给定一个数字串,找出其map back的字符串总和,比如26可以对应到Z或者BF,所以return 2。View Code class Solution { //递归解法 int numDecoding(string s) { return helper(s, 0); } int h... 阅读全文

posted @ 2013-02-10 14:46 梁霄 阅读(173) 评论(0) 推荐(0)

2013年2月4日

字符串相关的结构和算法

摘要: 字符串本质上是字符的数组,很多算法题与此相关。a. 判断一个字符串是否是回文,忽略非ASCII值,忽略大小写。比如"A man, a plan, a canal: Panama"就是一个合法的回文字符串。View Code class Solution{ bool isPalindrome(string s) { if (s.empty()) return true; int start = 0; int end = s.size() - 1; while (start < end){ if (!isLette... 阅读全文

posted @ 2013-02-04 14:29 梁霄 阅读(180) 评论(0) 推荐(0)

2013年1月25日

二叉树相关的数据结构和算法

摘要: 1. 二叉树(binary tree):最基本树型结构,每个结点最多有两个子节点,分别成为左子节点(left child node)和右子节点(right child node)。相关题目:a. 给定根结点,计算二叉树的最大深度。View Code //递归解法class Solution {public:int maxDepth(TreeNode* root){ if (root == NULL) return 0; if (root->left == NULL && root->right == NULL) return 1; if (root->left 阅读全文

posted @ 2013-01-25 01:25 梁霄 阅读(302) 评论(0) 推荐(0)

2013年1月2日

读书笔记:Sed & Awk 之 Awk篇

摘要: 1. Awk's programming model: The main loop in awk is a routine that reads one line of input from a file and makes it avaiblable for processing. You can use BEGIN/END to execute commands before/after the loop.2. Similar to sed, printing matched line content is the default behavior if no other acti 阅读全文

posted @ 2013-01-02 14:32 梁霄 阅读(246) 评论(0) 推荐(0)

2012年12月30日

shell script小结

摘要: 发现了一个巨赞的shell入门攻略,http://nixsrv.com/llthw,learn Linux the hard way, 虽然用的是bash做示例,但是大部分内容对于所有的shell都是适用的。1. IO内容的导入导出:ls > myfiles #Note if 'myfiles' file exist in your current directory it will be overwritten without any type of warning.date >> myfiles#To output Linux-commands resul 阅读全文

posted @ 2012-12-30 04:32 梁霄 阅读(283) 评论(0) 推荐(0)

2012年12月18日

编译器的学习笔记

摘要: 以前一直觉得编译器的内容过于底层和抽象,在如今高级语言流行的今天,掌握编译器的细节并没有很大的价值。不过,这一年多的工作经验让我觉得,知其然而且知其所以然是很关键的,而且对于做技术的人来说,长远的pay off会更大。记得自己有时候在编程或者调试的时候被一些小问题卡住,一卡就是一下午。但是组里的senior打眼一看就大约知道问题是什么,如何解决。所以说,在工作的初期,还是要求根问底,把基础打牢,才能在后期有大幅度的飞跃。扯回编译器,我学习的资料主要是standford的complier这门课,根据我目前的感觉,这个online course的讲解是我见过的最好的编译器课程,语言很清晰,而且有非 阅读全文

posted @ 2012-12-18 06:15 梁霄 阅读(308) 评论(0) 推荐(0)

2012年11月26日

java多线程学习心得——concurrent programming in java读书笔记

摘要: 对象方法内加锁的三原则:1. 对于更新对象方法内部成员的时候,一定要加锁。2. 读取对象内部可能被更新的状态字段的时候,加锁。3. 在调用其他对象方法的时候,千万别加锁。(目的是防止互锁,而且避免锁住当前对象)classParticle{protectedintx;protectedinty;protectedfinalRandomrng=newRandom();publicParticle(intx,inty){this.x=x;this.y=y;}publicsynchronizedvoidmove(){x+=rng.nextInt(10)-5;y+=rng.nextInt(20)-10 阅读全文

posted @ 2012-11-26 14:46 梁霄 阅读(295) 评论(0) 推荐(0)

导航