1 package com.icl.saxon.sort; 2 3 18 19 public abstract class QuickSort { 20 21 35 36 public static void sort(Sortable a, int lo0, int hi0) { 37 int lo = lo0; 38 int hi = hi0; 39 40 if ( hi0 > lo0) { 41 44 int mid = ( lo0 + hi0 ) / 2; 45 46 while ( lo <= hi ) { 48 51 while (( lo < hi0 ) && ( a.compare(lo, mid) < 0 )) 52 ++lo; 53 54 57 while (( hi > lo0 ) && ( a.compare(hi, mid) > 0 )) 58 --hi; 59 60 if ( lo <= hi ) { 62 if (lo!=hi) { 63 a.swap(lo, hi); 64 if (lo==mid) { 67 mid=hi; 68 } else if (hi==mid) { 69 mid=lo; 70 } 71 } 72 ++lo; 73 --hi; 74 } 75 } 76 77 80 if ( lo0 < hi ) 81 sort( a, lo0, hi ); 82 83 86 if ( lo < hi0 ) 87 sort( a, lo, hi0 ); 88 } 89 } 90 91 } 92 93 94 | Popular Tags |