标签:sizeof ios fine eof mergesort 排序 name return lse
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
void mergeSort(int a[], int s, int e, int temp[]) {
if (s < e) {
int m = s + (e - s) / 2;
mergeSort(a, s, m, temp);
mergeSort(a, m+1, e, temp);
mergeSort(a, m+1, e, temp);
merge(a, s, m, e, temp);
}
}
void merge(int a[], int s, int m, int e, int temp[]) {
int pb = 0;
int p1 = s, p2 = m + 1;
while (p1 <= m && p2 <= e) {
if (a[p1] < a[p2]) {
temp[pb++] = a[p1++];
}
else {
temp[pb++] = a[p2++];
}
}
while (p1 <= m) {
temp[pb++] = a[p1++];
}
while (p2 <= m) {
temp[pb++] = a[p2++];
}
for (int i = 0; i < e-s+1; i++) {
a[i] = temp[i];
}
}
int main()
{
int a[10] = { 13,27,19,2,8,12,2,8,30,89 };
int b[10];
int size = sizeof(a) / sizeof(int);
mergeSort(a, 0, size - 1, b);
for (int i = 0; i < size; i++) {
cout << a[i] << ",";
}cout << endl;
return 0;
}
标签:sizeof ios fine eof mergesort 排序 name return lse
原文地址:https://www.cnblogs.com/lijiahui-123/p/12363248.html