package labone.insertionsort;

import static labone.insertionsort.Driver.*;

public class InsertionSort {
	
	public static void linearSearch(int[] array, int key) {
		boolean foundFlag = false;
		for (int i = 0; i < array.length; i++) {
			if (array[i] == key) {
                stopTimer();
                foundFlag = true;
                System.out.println("Linear search returned key " + key
                        + " at index " + i + " in " + timeElapsed
                        + " millisecond(s).");
                break;
			}
		}
		if (!foundFlag) {
            stopTimer();
            System.out.println(Integer.MIN_VALUE);
            System.out.println("Linear search could not find the key. Time" +
                    " elapsed is " + timeElapsed + " millisecond(s).");
        }
	}

	public static int binarySearch(int[] array, int key, int min, int max) {
        if (max < min) {
            stopTimer();
            System.out.println(Integer.MIN_VALUE + "\nBinary search could not "
                    + "find the key. Time elapsed is " + 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 {
                stopTimer();
                System.out.println("Binary search returned key " + key
                        + " at index " + mid + " in " + timeElapsed
                        + " millisecond(s).");
                return mid;
            }
        }
	}

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

    private static void stopTimer() {
        timeFinal = System.nanoTime();
        System.out.println("timeFinal: " + timeFinal);
        timeElapsed = (timeFinal - timeInitial);
    }
}

@@ -28,54 +28,8 @@
 t;%0A%0A
-import static labone.insertionsort.Driver.*;%0A%0A
 publ
@@ -57,11 +57,25 @@
 t %7B%0A
-%09%0A%09
+        %0A        
 publ
@@ -126,18 +126,32 @@
  key) %7B%0A
-%09%09
+                
 boolean 
@@ -169,18 +169,32 @@
  false;%0A
-%09%09
+                
 for (int
@@ -230,62 +230,54 @@
 ) %7B%0A
-%09%09%09if (array%5Bi%5D == key) %7B%0A                stopTimer();
+                        if (array%5Bi%5D == key) %7B
 %0A   
@@ -424,32 +424,39 @@
  + i + %22 in %22 + 
+Driver.
 timeElapsed%0A    
@@ -525,19 +525,68 @@
 ak;%0A
-%09%09%09%7D%0A%09%09%7D%0A%09%09
+                        %7D%0A                %7D%0A                
 if (
@@ -607,35 +607,24 @@
             
-stopTimer()
 ;%0A          
@@ -771,32 +771,39 @@
  elapsed is %22 + 
+Driver.
 timeElapsed + %22 
@@ -835,13 +835,27 @@
   %7D%0A
-%09%7D%0A%0A%09
+        %7D%0A%0A        
 publ
@@ -952,33 +952,8 @@
 ) %7B%0A
-            stopTimer();%0A
     
@@ -1081,24 +1081,31 @@
 psed is %22 + 
+Driver.
 timeElapsed%0A
@@ -1492,37 +1492,8 @@
 e %7B%0A
-                stopTimer();%0A
     
@@ -1611,24 +1611,31 @@
  + %22 in %22 + 
+Driver.
 timeElapsed%0A
@@ -1737,9 +1737,16 @@
   %7D%0A
-%09
+        
 %7D%0A%0A 
@@ -2105,195 +2105,7 @@
    %7D
-%0A%0A    private static void stopTimer() %7B%0A        timeFinal = System.nanoTime();%0A        System.out.println(%22timeFinal: %22 + timeFinal);%0A        timeElapsed = (timeFinal - timeInitial);%0A    %7D
 %0A%7D%0A

Update InsertionSort.java