Question
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[]
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();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started