Binary search and fast sorting algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.