?????????????????????????????????????????磬???????????l??1ū????……?????????!
#include<iostream>
#include<algorithm>
using namespace std;
void Merge(int *initList?? int *mergedList?? const int l?? const int m?? const int n )
//n??????Ч?????????????????????????0?????????????????????Ч??????±?
//l??????????Ч??????±?m??????????Ч??????????????±?
{
int i1?? i2?? iResult;
for (i1 = l?? i2 = m + l?? iResult = l; i1 <= m && i2 <= n; iResult++)
{
if (initList[i1] <= initList[i2])
mergedList[iResult] = initList[i1++];
else
mergedList[iResult] = initList[i2++];
}
copy(initList + i1?? initList + m + 1?? mergedList + iResult);
copy(initList + i2?? initList + n + 1?? mergedList + iResult);
}
void MergePass(int *initList??int *resultList??const int n??const int s)
{
int i;
for (i = 1; i <= (n - 2 * s + 1); i += 2 * s)
Merge(initList?? resultList?? i?? i+s-1 ?? i+2*s-1);
if ((i + s - 1) < n)
Merge(initList?? resultList?? i?? i + s - 1?? n);
else
copy(initList + i?? initList + n + 1?? resultList + i);
}
int main()
{
int m[] = { 0??26??5??77??1?? 61??11??59??15??48??19 };//a[0]????
int n[11] = {0};
MergePass(m?? n?? 10?? 1);
for (int i = 1; i < 11;i++)
{
cout << n[i] << " ";
}
cout << endl;
MergePass(n?? m?? 10?? 2);
for (int i = 1; i < 11; i++)
{
cout << m[i] << " ";
}
cout << endl;
MergePass(m?? n?? 10?? 4);
for (int i = 1; i < 11; i++)
{
cout << n[i] << " ";
}
cout << endl;
MergePass(n?? m?? 10?? 8);
for (int i = 1; i < 11; i++)
{
cout << m[i] << " ";
}
cout << endl;
return 0;
}