1. Engineering
  2. Computer Science
  3. im trying to find out what is wrong with my...

Question: im trying to find out what is wrong with my...

Question details

I'm trying to find out what is wrong with my code?

package DriverClass;

public class DriveClass {

public static void main(String[] args) {

int a[] = {3, 2, 5, 6, 1};

InsertionSortClass insertion = new InsertionSortClass();

System.out.print("The original list : ");

System.out.println();

insertion.printArray(a);

System.out.println();

System.out.println("The list after insertionSort : ");

System.out.println();

insertion.insertionSort(a);

}

}

package DriverClass;

public interface SortADTInterface {

public void insertionSort(int arr[]);

public void printArray(int arr[]);

}

package DriverClass;

public class InsertionSortClass implements SortADTInterface{

public void insertionSort(int[] arr) {

int i = arr.length;

for (int j = 1; j < i; j++) {

int value = arr[j];

int k = j - 1;

while ((j > 0) && (arr[i] > value)) {

arr[i + 1] = arr[k];

i--;

}

arr[i+1] = value;

}

}

public void printArray(int[] arr) {

for (int i = 0; i < arr.length; i++) {

System.out.print(arr[i] + " ");

}

System.out.println();

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution