PAT1089【归并排序】

这题略。。。恶心。。
他说归并排序依次是相邻有序两块合并,而一向打惯了递归???

#include 
using namespace std;
typedef long long LL;

const int N=1e2+10;
int b[N];

void Merge(int a[], int temp[], int Left, int Mid, int Right)
{
    int i,tp=Left;
    int dis=Right-Left+1;
    int Leftend=Mid-1;
    while(Left<=Leftend&&Mid<=Right)
        if(a[Left]=0;j--)
        {
            if(a[j]=0;j--)
            {
                if(a[j]=n) break;
      Right=Left+2*dis-1;
      if(Right>=n)
      {
        Right=n-1;
        Merge(a,temp,Left,Mid,Right);  
        break;
      }
      else
        Merge(a,temp,Left,Mid,Right);
      Left=Right+1;
      if(Left>=n) break;
    }
    dis*=2;
    if(Check(a,n))
    {
      Left=0;
      while(1)
      {
        Mid=Left+dis;
        if(Mid>=n) break;
        Right=Left+2*dis-1;
        if(Right>=n)
        {
          Right=n-1;
          Merge(a,temp,Left,Mid,Right);  
          break;
        }
        else
          Merge(a,temp,Left,Mid,Right);
        Left=Right+1;
        if(Left>=n) break;
      }

      puts("Merge Sort");
            for(int k=0;k


转载于:https://www.cnblogs.com/keyboarder-zsq/p/6777368.html

你可能感兴趣的:(PAT1089【归并排序】)