二路归并算法 C语言版本

void MergeSort(int A[],int temp[],int let,int right){
   if(left<right){
       int mid = (left+right)/2;  
       MergeSort(A,temp,left,mid);
       MergeSort(A,temp,mid+1,right);
       Merge(A,temp,left,mid,right);
  }
}

void Merge(int A[],int temp[],int left,int mid,int right){
       int index1,index2,current;
       for(current=left;current<=right;current++){
           temp[current++] = A[current++];
   }//赋值给temp[]
       for(index1=left,index2=mid+1,current=left;
                 index1<=mid&&index2<=right;current++){
           if(temp[index1]<temp[index2]){
              A[current]=temp[index1++];
      }
             else{
              A[current]=temp[index2++];
}
   }
        while(index1<=mid)  A[current++]= temp[index1++];
        while(index2<=right) A[current++] = temp[index2++];
}//Merge  

  

你可能感兴趣的:(C++,c,算法,C#)