sorting - Quicksort in Java - space is bigger than number -
i wrote code read data data.txt
, quicksort
them , write data2.txt
input format is:
145 567 12 3456 1345 67
i need output in format:
12 3456 145 567 1345 67
but get:
12 3456 1345 67 145 567
here code:
private static arraylist<string> sort(arraylist<string> ar, int lo, int hi){ if (lo < hi){ int splitpoint = partition(ar, lo, hi); sort(ar, lo, splitpoint); sort(ar, splitpoint +1, hi); } return ar; } private static int partition(arraylist<string> ar, int lo, int hi){ string pivot = ar.get(lo); lo--; hi++; while (true){ lo++; while (lo<hi && ar.get(lo).compareto(pivot) < 0){ lo++; } hi--; while (hi>lo && ar.get(hi).compareto(pivot) >= 0){ hi--; } if (lo<hi){ swap(ar, lo, hi); }else { return hi; } } } private static arraylist<string> swap(arraylist<string> ar, int a, int b){ string temp = ar.get(a); ar.set(a, ar.get(b)); ar.set(b, temp); return ar; }
thank help.
Comments
Post a Comment