1 36 37 40 41 48 class BubbleSortAlgorithm extends SortAlgorithm { 49 void sort(int a[]) throws Exception { 50 for (int i = a.length; --i>=0; ) { 51 boolean swapped = false; 52 for (int j = 0; j<i; j++) { 53 if (stopRequested) { 54 return; 55 } 56 if (a[j] > a[j+1]) { 57 int T = a[j]; 58 a[j] = a[j+1]; 59 a[j+1] = T; 60 swapped = true; 61 } 62 pause(i,j); 63 } 64 if (!swapped) 65 return; 66 } 67 } 68 } 69 | Popular Tags |