@@ -0,0 +1,1405 @@
+package com.matao.fundamentals.exercises;%0A%0Aimport edu.princeton.cs.algs4.StdOut;%0A%0A/**%0A * Created by matao on 2018/8/22.%0A * %3Cp%3E%0A * Write a version of BinarySearch and traces the method calls.%0A * Each time the recursive method is called,%0A * print the argument values lo and hi, indented by the depth of the recursion.%0A * Hint: Add an argument to the recursive method that keeps track of the depth.%0A */%0Apublic class Ex_1_1_22 %7B%0A%0A    public static int rank(int target, int%5B%5D a) %7B%0A        return rank(target, a, 0, a.length - 1, 0);%0A    %7D%0A%0A    public static int rank(int target, int%5B%5D a, int low, int high, int depth) %7B%0A        for (int i = 0; i %3C depth; i++) %7B%0A            StdOut.print(%22 %22);%0A        %7D%0A        StdOut.printf(%22low = %25d, high = %25d%5Cn%22, low, high);%0A%0A        if (low %3E high) %7B%0A            return -1;%0A        %7D%0A        int mid = low + (high - low) / 2;%0A        if (target %3C a%5Bmid%5D) %7B%0A            return rank(target, a, low, mid - 1, depth + 1);%0A        %7D else if (target %3E a%5Bmid%5D) %7B%0A            return rank(target, a, mid + 1, high, depth + 1);%0A        %7D else %7B%0A            return mid;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D a = %7B1, 2, 3, 4, 6, 7, 8, 9, 12%7D;%0A        int key = 5;%0A        int pos = rank(key, a);%0A        if (pos == -1) %7B%0A            StdOut.print(%22not found!%22);%0A        %7D else %7B%0A            StdOut.printf(%22position = %25d%22 + pos);%0A        %7D%0A    %7D%0A%7D%0A

add solution to exercise 1.1.22