public class Main { public static void main(String[] args) { } int[] arr = {1, -1, 3, 2, -7, -5, 11, 6}; arr = moveNegative (arr); for (int i : arr) { } System.out.print(i + 11 } 1 usage public static int[] moveNegative(int[] arr) { int[] positive = new int[arr.length]; int[] negative = new int[arr.length]; int positiveIndex = 0; int negative Index = 0; for (int i 0; i < arr.length; i++) { if (arr[i] < 0) { } "); negative [negativeIndex++] = arr[i]; } else { positive [positiveIndex++] = arr[i]; } } for (int i = 0; i < negativeIndex; i++) { negative [i]; arr[i] = for (int i = 0; i < positiveIndex; i++) { arr[negativeIndex + i] = positive [i]; } return arr;

icon
Related questions
Question

Prove that the algorithm takes (?(?)) running time to compute this task. Please formulate the
sum equation for this proof and explain. I am a bit confused.

public class Main {
public static void main(String[] args) {
int[] arr = {1, -1, 3, 2, -7, -5, 11, 6};
arr = moveNegative (arr);
for (int i : arr) {
}
}
لم
}
11
System.out.print(i + ");
1 usage
public static int[] moveNegative(int[] arr) {
int[] positive = new int[arr.length];
int[] negative = new int[arr.length];
int positiveIndex = 0;
int negative Index 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < 0) {
}
negative [negativeIndex++] = arr[i];
} else {
positive [positiveIndex++] = arr[i];
}
}
}
for (int i 0; i < negativeIndex; i++) {
arr[i] = negative [i];
0; i < positiveIndex; i++) {
arr[negativeIndex + i] = positive [i];
for (int i =
}
return arr;
Transcribed Image Text:public class Main { public static void main(String[] args) { int[] arr = {1, -1, 3, 2, -7, -5, 11, 6}; arr = moveNegative (arr); for (int i : arr) { } } لم } 11 System.out.print(i + "); 1 usage public static int[] moveNegative(int[] arr) { int[] positive = new int[arr.length]; int[] negative = new int[arr.length]; int positiveIndex = 0; int negative Index 0; for (int i = 0; i < arr.length; i++) { if (arr[i] < 0) { } negative [negativeIndex++] = arr[i]; } else { positive [positiveIndex++] = arr[i]; } } } for (int i 0; i < negativeIndex; i++) { arr[i] = negative [i]; 0; i < positiveIndex; i++) { arr[negativeIndex + i] = positive [i]; for (int i = } return arr;
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions