void merge(vector
<int>& A
, int low
, int mid
, int high
) {
vector
<int> B
= A
;
int i
= low
, j
= mid
+ 1, pos
= i
;
while(i
<= mid
&& j
<= high
) {
if (B
[i
] <= B
[j
]) {
A
[pos
++] = B
[i
++];
} else {
A
[pos
++] = B
[j
++];
}
}
while (i
<= mid
) A
[pos
++] = B
[i
++];
while (j
<= high
) A
[pos
++] = B
[j
++];
}
void mergeSort(vector
<int>& A
, int low
, int high
) {
if(low
< high
) {
int mid
= (low
+ high
) / 2;
mergeSort(A
, low
, mid
);
mergeSort(A
, mid
+ 1, high
);
merge(A
, low
, mid
, high
);
}
}
转载请注明原文地址:https://tech.qufami.com/read-6576.html