-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobeNegative.java
More file actions
38 lines (32 loc) · 859 Bytes
/
Copy pathMobeNegative.java
File metadata and controls
38 lines (32 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class MobeNegative {
public static void main(String[] args) {
int[] arr = { -12, 11, -13, -5, 6, -7, 5, -3, -6 };
moveArr(arr);
printArr(arr);
}
static void printArr(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
static void moveArr(int[] arr) {
int lo = 0;
int temp = 0;
int high = arr.length - 1;
while (lo <= high) {
if (arr[lo] < 0) {
lo++;
}
if (arr[lo] > 0) {
if (arr[high] > 0) {
high--;
} else {
temp = arr[lo];
arr[lo] = arr[high];
arr[high] = temp;
high--;
}
}
}
}
}