Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sorts this list according to the order induced by the specified
- * Comparator.
- * */
- public void sort(Comparator<T> c) {
- //Arrays.sort(arrayList, FIRST_ELEMENT, arrayList.length);
- // using quick sort
- T obj1 = arrayList[FIRST_ELEMENT], obj2 = arrayList[FIRST_ELEMENT+1];
- int value;
- T[] temparr = (T[]) new Object[arrayList.length];
- for(int i = 0; i < temparr.length; i++) {
- if(temparr[i] != null) {
- obj1 = temparr[i];
- }
- for(int j = 1; j < arrayList.length; j++) {
- obj2 = arrayList[j];
- value = c.compare(obj1, obj2);
- if(value > 0) {
- temparr[i] = obj2;
- } else if(value == 0) {
- temparr[i] = obj1;
- temparr[i+1] = obj2;
- } else {
- temparr[i] = obj1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement