Some implementation of insertion sort is very similar to the concept of bubble sort. So I was always confused and want to find ways to distinguish them better.
For insertion sort, the key assumption and loop-invariant is: the sequence infront is already sorted.
So, when inserting current node into correct position, comparison stops whenever encounter smaller nodes.
For bubble sort, there is no such assumption. So always need comparison.
References:
http://blog.csdn.net/morewindows/article/details/6665714
http://www.cnblogs.com/yeguo/archive/2013/05/14/3078202.html
http://blog.csdn.net/notalmost/article/details/7535523
General Coding
Thursday, December 19, 2013
Friday, December 13, 2013
Eclipse shortcut override by Sogou
I use CTRL+SPACE shortcut in eclipse quite ofter. After installed Sogou Chinese input, it got override. Very annoying.
Found a solution here:
http://superuser.com/questions/327479/ctrl-space-always-toggles-chinese-ime-windows-7
Found a solution here:
http://superuser.com/questions/327479/ctrl-space-always-toggles-chinese-ime-windows-7
if v.s. else if
I am always confused about when to use a bunch of "if", when to use "else if".
For "a bunch of if" I mean:
if(cond1){}
if(cond2){}
if(cond3){}
For "else if" I mean:
if(cond1){}
else if(cond2){}
else if(cond3){}
else if(cond4){}
When you want the conditions to be mutually exclusive, use "else if";
if not, you can use a bunch of "if".
Following this rule, it will be easier to "think-it-through" when debugging.
For "a bunch of if" I mean:
if(cond1){}
if(cond2){}
if(cond3){}
For "else if" I mean:
if(cond1){}
else if(cond2){}
else if(cond3){}
else if(cond4){}
When you want the conditions to be mutually exclusive, use "else if";
if not, you can use a bunch of "if".
Following this rule, it will be easier to "think-it-through" when debugging.
Subscribe to:
Posts (Atom)