Skip to content

Commit

Permalink
posNegSort done
Browse files Browse the repository at this point in the history
  • Loading branch information
nberserk committed Jun 2, 2015
1 parent db09186 commit b5b3d53
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions java/src/crackcode/PositiveNegativeSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package crackcode;

import java.util.Arrays;

public class PositiveNegativeSort {

static boolean sDebug = true;

public static void main(String[] args) {
int[] n = {-1, 1, 3, -2, 2, 8};

int[] n2 = { -1, 1, 4, -3, 7, 2, 9, -11 };
customSort(n2);
}

static void customSort(int[] n){
int N = n.length;
int[] org = Arrays.copyOf(n, N);

int d = N - 1;
for (int i = N - 1; i >= 0; i--) {
if (org[i] >= 0) {
n[d] = org[i];
d--;
}
}
d = 0;
for (int i = 0; i < N; i++) {
if (org[i] >= 0) {
} else {
n[d] = org[i];
d++;
}
}

print(Arrays.toString(n));
}

static void print(String s){
if (sDebug) {
System.out.println(s);
}
}
}

0 comments on commit b5b3d53

Please sign in to comment.