1 22 package test.dbc.java; 23 24 import java.util.ArrayList ; 25 import java.util.Collections ; 26 import java.util.Comparator ; 27 28 34 public class Sorter 35 { 36 40 public static int[] sort(int[] unsorted) 41 { 42 ArrayList list = new ArrayList (); 44 45 for (int i = 0 ; i < unsorted.length ; i++) 46 { 47 list.add(new Integer (unsorted[i])); 48 } 49 50 Collections.sort(list, 51 new Comparator () 52 { 53 public boolean equals(Object obj) 54 { 55 return false; 56 } 57 58 public int compare(Object o1, Object o2) 59 { 60 int i1 = ((Integer )o1).intValue(); 61 int i2 = ((Integer )o2).intValue(); 62 63 if (i1 < i2)return -1; 64 if (i1 == i2)return 0; 65 return 1; 66 } 67 }); 68 69 int[] sorted = new int[unsorted.length]; 70 for (int i = 0 ; i < list.size() ; i++) 71 { 72 sorted[i] = ((Integer )list.get(i)).intValue(); 73 } 74 return sorted; 75 } 76 77 81 public static int[] brokenSort(int[] unsorted) 82 { 83 return unsorted; 84 } 85 } 86 | Popular Tags |