1 36 37 40 41 48 class BidirBubbleSortAlgorithm extends SortAlgorithm { 49 void sort(int a[]) throws Exception { 50 int j; 51 int limit = a.length; 52 int st = -1; 53 while (st < limit) { 54 st++; 55 limit--; 56 boolean swapped = false; 57 for (j = st; j < limit; j++) { 58 if (stopRequested) { 59 return; 60 } 61 if (a[j] > a[j + 1]) { 62 int T = a[j]; 63 a[j] = a[j + 1]; 64 a[j + 1] = T; 65 swapped = true; 66 } 67 pause(st, limit); 68 } 69 if (!swapped) { 70 return; 71 } 72 else 73 swapped = false; 74 for (j = limit; --j >= st;) { 75 if (stopRequested) { 76 return; 77 } 78 if (a[j] > a[j + 1]) { 79 int T = a[j]; 80 a[j] = a[j + 1]; 81 a[j + 1] = T; 82 swapped = true; 83 } 84 pause(st, limit); 85 } 86 if (!swapped) { 87 return; 88 } 89 } 90 } 91 } 92 | Popular Tags |