2. Search a sorted array for the count of k.
Write a method that takes a sorted array A and a key k and returns the count of k.
[Hint: Binary search commonly asks for the index of any element of a sorted array. Find the index of the first and last occurrence of k in A.]
3. Sort a given Perl hash by key without using Perl function sort().
4. Implement a queue by using stacks.
[Hint: Implement two methods enqueue() and dequeue().]
6. Fibonacci spiral.
We move our finger according to Fibonacci spiral from the origin O = (0, 0).
We will pass (1, 1), (0, 2), (-2, 0), (1, -3) in sequence. We label the sequence in Pi, that is, P1 = (1, 1), P2 = (0, 2), P3 = (-2, 0), P4 = (1, -3) and so on. Now write a method to return the coordinate of Pn.
沒有留言:
張貼留言