New Semester!
Today is the first day of new semester. And unluckily only one course is successfully registered so far. Courses of CS department are too popular. Hope everything will be all right in new semester.
Read full article →Cracking the Coding Interview: Q 16.5 Run Threads In Sequence
With the help of C++11 multi-threading library, this question about running threads in sequence can be easily implemented. Both implementations below is public on GitHub. Question Suppose we have the following code: [code] The same instance of Foo will be passed to three different threads. Thread A will call first, thread B will call second, and thread C will call third. Design a mechanism to ensure that first is called before second and second is called before third.
Read full article →Fix UltiSnips Snippets Load Problem
To better use YouCompleteMe in Vim, I switched from SnipMate to UltiSnips, because UltiSnips can be integrated into YCM. I also installed snippets since UltiSnips offers an engine only. [code] But after I installed it with Vundle, it didn&8217;t work correctly. It only load &8216;all&8217; filetype snippets. You can check this by typing [code] in Vim. If only &8216;all.snippets&8217; appears, then here is the problem.
Read full article →Cracking the Coding Interview: Q 3.4 Hanoi Tower Problem
Although the Hanoi Tower problem very basic, by studying it, we learn thinking in recursive way. Generally we should analysis the base cases and reorganize the problem into subproblems. The different thing from 4th edition is that, in 5th edition, it&8217;s required to use stack to simulate the tower. Question In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower.The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints: (1) Only one disk can be moved at a time. (2) A disk is slid off the top of one tower onto the next tower. (3) A disk can only be placed on top of a larger disk. Write a program to move the disks from the first tower to the last using stacks.
Read full article →Cracking the Coding Interview: Q 2.6 Circular Linked List Problem
Recently I’m working on “Cracking the Coding Interview 5th Edition”. All my solutions are public on Github. For this typical question about circular linked list in chapter 2, the way to solve it is a bit tricky. Question Given a circular linked list, implement an algorithm which returns node at the beginning of the loop. DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list. EXAMPLE Input: A - B - C - D - E - C [the same C as earlier] Output: C
Read full article →