1 /********** Two-point find *****************/2 intHalf_find (int*num,intSizeinta)3 {4 intI=0;5 intlow=0;6 inthigh=size-1;7 intMid//Record Middle Position8 while(low<=High )9 {TenMid = (Low+high)/2; One if(Num[mid] = =a) A returnMid//go back to your location - if(Num[mid] >a) -High = mid-1;//minus the big half. the if(Num[mid] <a) -Low = mid+1;//minus that little half. - } - return false;//didn't find + } - /********** fast sorting algorithm *****************/ + voidQuickSort (CharS[],intLowintHigh ) A { at inti; - intLast//location of the record Datum - if(Low//operation occurs when the number of elements in the array is greater than 1 o'clock - { -Last=low;//Select the first element as a datum - //separate the less than the reference element from the reference element, and last record the bounds of their separation in for(i=low+1; i<=high;i++) - { to if(s[i]<S[low]) +Swap (s,++last,i); - } the *Swap (S,last,low);//The datum element is exchanged with the boundary, so that the datum element is on either side greater than the other; $QuickSort (s,low,last-1);//recursive ordering of left intervalPanax NotoginsengQuickSort (s,last+1, high);//recursive ordering of right intervals - } the } + /*swap two elements in an array*/ A voidSwapCharS[],intIintj) the { + inttemp; -temp=S[i]; $s[i]=S[j]; $s[j]=temp; -}
Binary search and fast sorting algorithm