Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help please i don't understand this java code. please help me fully understand and what is ? and : i have never seen this symbol

help please i don't understand this java code. please help me fully understand and what is ? and : i have never seen this symbol before

public class mergesort {

public static void main(String[] args) {

int[] intArray = { 20, 35, -15, 7, 55, 1, -22 };

mergeSort(intArray, 0, intArray.length);

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

System.out.println(intArray[i]);

}

}

// { 20, 35, -15, 7, 55, 1, -22 }

public static void mergeSort(int[] input, int start, int end) {

if (end - start < 2) {

return;

}

int mid = (start + end) / 2;

mergeSort(input, start, mid);

mergeSort(input, mid, end);

merge(input, start, mid, end);

}

// { 20, 35, -15, 7, 55, 1, -22 }

public static void merge(int[] input, int start, int mid, int end) {

if (input[mid - 1] <= input[mid]) {

return;

}

int i = start;

int j = mid;

int tempIndex = 0;

int[] temp = new int[end - start];

while (i < mid && j < end) {

temp[tempIndex++] = input[i] <= input[j] ? input[i++] : input[j++];

}

System.arraycopy(input, i, input, start + tempIndex, mid - i);

System.arraycopy(temp, 0, input, start, tempIndex);

}

}

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago