Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago