标签:pac main nbsp getc 归并 assert namespace bsp return
#include<iostream>
#include<assert.h>
using namespace std;
int temp[20];
void domerge(int*a, int left, int right){
for (int i = left; i <= right; i++)
temp[i] = a[i];
int low = left;
int mid = (left + right) / 2;
int high = (left + right) / 2 + 1;
for (int i = left; i <= right; i++){
if (low>mid){
a[i] = temp[high++];
}
else if (high>right){
a[i] = temp[low++];
}
else if (temp[low]<temp[high]){
a[i] = temp[low++];
}
else {
a[i] = temp[high++];
}
}
}
void merge(int*a, int left, int right){
if (left >= right) return;
int mid = (left + right) / 2;
merge(a, left, mid);
merge(a, mid + 1, right);
domerge(a, left, right);
}
int main(){
int temp[12] = { 81, 4, 6, 2, 33, 6, 1, 6, 3, 4, 3, 0 };
merge(temp, 0, 11);
for (int i = 0; i < 12; i++)
cout << temp[i] << " ";
getchar();
return 0;
}
标签:pac main nbsp getc 归并 assert namespace bsp return
原文地址:https://www.cnblogs.com/liangyc/p/11646064.html