Answered step by step
Verified Expert Solution
Question
1 Approved Answer
what kind of sorting is this? (computer science JAVA) public int[] array; public int[] tempArr; public int length; public void sort(String inputArr[]) { array =
what kind of sorting is this? (computer science JAVA)
public int[] array; public int[] tempArr; public int length; public void sort(String inputArr[]) { array = inputArr; length = inputArr.length; tempArr = new String[length]; doSort(0, length - 1); } private void doSort(int lowerIndex, int higherIndex) { if (lowerIndex < higherIndex) { int middle = lowerIndex + (higherIndex - lowerIndex) / 2; doSort(lowerIndex, middle); doSort(middle + 1, higherIndex); doSomething(lowerIndex, middle, higherIndex); } } private void doSomething(int lowerIndex, int middle, int higherIndex) { for (int i = lowerIndex; i <= higherIndex; i++) { tempArr[i] = array[i]; } int i = lowerIndex; int j = middle + 1; int k = lowerIndex; while (i <= middle && j <= higherIndex) { if (tempArr[i] <= tempArr[j]) { array[k] = tempArr[i]; i++; } else { array[k] = tempArr[j]; j++; } k++; } while (i <= middle) { array[k] = tempArr[i]; k++; i++; } }
Also, how many times will doSomething be called if an arraycolors contains the values blue green orange red purple and sort(colors) is called?
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