1 package junit.runner; 2 3 import java.util.Vector ; 4 5 10 public class Sorter { 11 public static interface Swapper { 12 public void swap(Vector values, int left, int right); 13 } 14 15 public static void sortStrings(Vector values , int left, int right, Swapper swapper) { 16 int oleft= left; 17 int oright= right; 18 String mid= (String )values.elementAt((left + right) / 2); 19 do { 20 while (((String )(values.elementAt(left))).compareTo(mid) < 0) 21 left++; 22 while (mid.compareTo((String )(values.elementAt(right))) < 0) 23 right--; 24 if (left <= right) { 25 swapper.swap(values, left, right); 26 left++; 27 right--; 28 } 29 } while (left <= right); 30 31 if (oleft < right) 32 sortStrings(values, oleft, right, swapper); 33 if (left < oright) 34 sortStrings(values, left, oright, swapper); 35 } 36 } | Popular Tags |