!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! isort.h Sorting functions ! V 1.0 L. Ross Raszewski ! ! This is a fairly simple library that implements quicksort ! functionality for arrays in inform. ! sortwords(array,begin,end,func); ! sorts a word array from -->begin to -->(end-1) ! func(x,y) should return > 0 if x should come BEFORE y, ! < 0 if x should come AFTER y, ! ==0 if the order of x and y doesn't matter. ! ! sortbytes provides similar functionality for byte arrays. ! ! e-mail me at rraszews@acm.org [ sortwords arr begin end func i j temp; i=begin+1; j=end-1; if ((end-begin)<=1) return; while(ij,arr-->begin)<0) { j--; } while(ii,arr-->begin)>0) { i++; } if (ii; arr-->i=arr-->j; arr-->j=temp; } } if (func(arr-->begin,arr-->i)<0) { temp=arr-->begin; arr-->begin=arr-->i; arr-->i=temp; j++; } sortwords(arr,begin,i,func); sortwords(arr,j,end,func); ]; [ sortbytes arr begin end func i j temp; i=begin+1; j=end-1; if ((end-begin)<=1) return; while(ij,arr->begin)<0) { j--; } while(ii,arr->begin)>0) { i++; } if (ii; arr->i=arr->j; arr->j=temp; } } if (func(arr->begin,arr->i)<0) { temp=arr->begin; arr->begin=arr->i; arr->i=temp; j++; } sortbytes(arr,begin,i,func); sortbytes(arr,j,end,func); ];