#includeint temp[100000]; int a[100000]; void guibing2(int low, int mid, int high) { int i, j, p; for (i = low, j = mid, p = low; i < mid && j <= high; p++) { if (a[i] < a[j]) { temp[p] = a[i++]; } else { temp[p] = a[j++]; } } while (i < mid) { temp[p++] = a[i++]; } while (j <= high) { temp[p++] = a[j++]; } for (i = low; i <= high; i++) { a[i] = temp[i]; } } void guibing1(int low, int high) { if (high > low) { int mid = (high + low) / 2; guibing1(low, mid); guibing1(mid + 1, high); guibing2(low, mid+1, high); } } int main() { int n; scanf("%d", &n); int i; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); } guibing1(1, n); for (i = 1; i <= n; i++) { printf("%d ",a[i]); } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)