package labone.insertionsort;

public class InsertionSort {
	
	public static void linearSearch(int[] array, int key) {
		boolean foundFlag = false;
        int index = 0;
		for (int i = 0; i < array.length; i++) {
			if (array[i] == key) {
                index = i;
                stopwatch();
                foundFlag = true;
                System.out.println("Linear search returned key " + key
                        + " at index " + i + " in " + Driver.timeElapsed
                        + " millisecond(s).");
                break;
			}
		}
		if (!foundFlag) {
            stopwatch();
            System.out.println(Integer.MIN_VALUE);
            System.out.println("Linear search could not find the key. Time" +
                    " elapsed is " + Driver.timeElapsed + " millisecond(s).");
        }
		return;
	}
	
	public static int binarySearch(int[] array, int key, int min, int max) {
        if (max < min) {
            stopwatch();
            System.out.println(Integer.MIN_VALUE + "\nBinary search could not "
                    + "find the key. Time elapsed is " + Driver.timeElapsed
                    + " millisecond(s).");
            return Integer.MIN_VALUE;
        }
        else {
            int mid = (min + (max - min) / 2);
            if (array[mid] > key) {
                return binarySearch(array, key, min, (mid - 1));
            } else if (array[mid] < key ) {
                return binarySearch(array, key, (mid + 1), max);
            } else {
                stopwatch();
                System.out.println("Binary search returned key " + key
                        + " at index " + mid + " in " + Driver.timeElapsed
                        + " millisecond(s).");
                return mid;
            }
        }
	}

    public static void insertionSort(int[] array) {
        int key;
        int i;
        for (int j = 1; j < array.length; j++) {
            i = j;
            while(i > 0 && array[i - 1] > array[i]) {
                key = array[i];
                array[i] = array[i - 1];
                array[i - 1] = key;
                i--;
            }
        }
        return;
    }

    private static void stopwatch() {
        Driver.timeFinal = System.currentTimeMillis();
        System.out.println("timeFinal: " + Driver.timeFinal);
        Driver.timeElapsed = (Driver.timeFinal - Driver.timeInitial);
    }
}
@@ -1895,24 +1895,52 @@
 gth; j++) %7B%0A
+            key = array%5Bj%5D;%0A
             
@@ -1944,16 +1944,20 @@
    i = j
+ - 1
 ;%0A      
@@ -1971,16 +1971,17 @@
 hile(i %3E
+=
  0 && ar
@@ -1993,24 +1993,19 @@
  - 1%5D %3E 
-array%5Bi%5D
+key
 ) %7B%0A    
@@ -2019,22 +2019,16 @@
     
- key =
  array%5Bi
 %5D;%0A 
@@ -2027,34 +2027,12 @@
 ay%5Bi
-%5D;%0A                array%5Bi
+ + 1
 %5D = 
@@ -2038,20 +2038,16 @@
  array%5Bi
- - 1
 %5D;%0A     
@@ -2061,26 +2061,11 @@
     
-array%5Bi - 1%5D = key
+i--
 ;%0A  
@@ -2070,32 +2070,25 @@
             
-    i--;
+%7D
 %0A           
@@ -2080,33 +2080,50 @@
   %7D%0A            
-%7D
+array%5Bi + 1%5D = key
 %0A        %7D%0A     
@@ -2372,8 +2372,9 @@
 %0A    %7D%0A%7D
+%0A

Update InsertionSort.java