Skip to content

Commit b5b3d53

Browse files
committed
posNegSort done
1 parent db09186 commit b5b3d53

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package crackcode;
2+
3+
import java.util.Arrays;
4+
5+
public class PositiveNegativeSort {
6+
7+
static boolean sDebug = true;
8+
9+
public static void main(String[] args) {
10+
int[] n = {-1, 1, 3, -2, 2, 8};
11+
12+
int[] n2 = { -1, 1, 4, -3, 7, 2, 9, -11 };
13+
customSort(n2);
14+
}
15+
16+
static void customSort(int[] n){
17+
int N = n.length;
18+
int[] org = Arrays.copyOf(n, N);
19+
20+
int d = N - 1;
21+
for (int i = N - 1; i >= 0; i--) {
22+
if (org[i] >= 0) {
23+
n[d] = org[i];
24+
d--;
25+
}
26+
}
27+
d = 0;
28+
for (int i = 0; i < N; i++) {
29+
if (org[i] >= 0) {
30+
} else {
31+
n[d] = org[i];
32+
d++;
33+
}
34+
}
35+
36+
print(Arrays.toString(n));
37+
}
38+
39+
static void print(String s){
40+
if (sDebug) {
41+
System.out.println(s);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)