Swift and merge sort for the quick version

Source: Internet
Author: User

class Sortclass:nsobject {func QuickSort (inout Array:[int]) {Self.quick (&array, left:0, right:array.count-1)} func Quickmain (InOut array:[int],varLeft:int,varRight:int)int{varsrcleft=Array[left] while(left<Right ) {             while(left<right&&array[right]>=srcleft) { Right--} Array[left]=Array[right] while(left<right&&array[left]<=srcleft) { Left++} Array[right]=Array[left]} Array[left]=SrcleftreturnLeft } func quick (inout Array:[int],varLeft:int,varright:int) {        if(left<Right ) {            varMiddle=self.quickmain (&Array, Left:left, Right:right) Self.quick (&array, Left:left, right:middle-1) Self.quick (&array, left:middle+1, Right:right)} } func Mergersort (InOut Array:[int]) {varTemparray=[int] (Count:array.count, repeatedvalue:1) Self.merger (&array, Temparray: &temparray, left:0, right:array.count-1)} func merger (InOut Array:[int],inout Temparray:[int],varLeft:int,varright:int) {        if(left<Right ) {            varMiddle= (left+right)/2 Self.merger (&array, Temparray: &Temparray, Left:left, Right:middle) Self.merger (&array, Temparray: &temparray, left:middle+1, Right:right) Self.mergermain (&array, Temparray: &temparray, Leftstart:left, Leftend:middle, rightstart:middle+1, Rightend:right)} } func Mergermain (InOut array:[int],inout temparray:[int],varLeftstart:int,varLeftend:int,varRightstart:int,varrightend:int) {        varindex=Leftstartvarrecoderleftstart=Leftstart;  while(leftstart<=leftend&&rightstart<=rightend) {            if(array[leftstart]<=Array[rightstart]) {Temparray[index++]=array[leftstart++]            }Else{Temparray[index++]=array[rightstart++]            }        }                 while(leftstart<=leftend) {Temparray[index++]=array[leftstart++]        }                 while(rightstart<=rightend) {Temparray[index++]=array[rightstart++]        }                 for(vari=recoderleftstart;i<=rightend;i++) {Array[i]=temparray[i] }}}

Learning Swift overall feels good. Spit Noise two points, 1 when the smart prompt is not friendly, 2 want to follow the version can have method access to the Modifier keyword added.

Swift and merge sort for the quick version

Related Article

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.