/Users/lyon/j4p/src/addBk/address/Sort.java

1    package addBk.address; 
2     
3    import java.util.Vector; 
4     
5     
6    public final class Sort { 
7        private Sort() { 
8        }; 
9     
10       private static void swap(Vector v, int i, int j) { 
11           Object o1 = v.elementAt(i); 
12           Object o2 = v.elementAt(j); 
13           v.setElementAt(o2, i); 
14           v.setElementAt(o1, j); 
15       } 
16    
17       public static void bubble(Vector v) { 
18           for (int i = v.size(); 
19                --i >= 0;) { 
20               boolean swapped = false; 
21               for (int j = 0; j < i; j++) { 
22                   Comparator c1 = (Comparator) 
23                           v.elementAt(j); 
24                   Comparator c2 = (Comparator) 
25                           v.elementAt(j + 1); 
26                   int c = c1.compare(c1, c2); 
27                   if (c > 0) 
28                       swap(v, j, j + 1); 
29               } 
30           } 
31       } 
32   }