插入排序还是堆排序 (25分)

10
3 1 2 8 7 5 9 4 6 0
1 2 3 7 8 5 9 4 6 0


Insertion Sort
1 2 3 5 7 8 9 4 6 0


10
3 1 2 8 7 5 9 4 6 0
6 4 5 1 0 3 2 7 8 9


Heap Sort
5 4 3 1 0 2 6 7 8 9

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int N;

void Insertion_Sort(int arr[], int brr[]) {
int flag = 0;
for (int i = 1; i <= N; ++i) {
sort(arr, arr + i);
if (flag) {
cout << "Insertion Sort" << endl << arr[0];
for (int j = 1; j < N; ++j)
cout << " " << arr[j];
exit(0);
}
if (equal(arr, arr + N, brr))
flag = 1;
}
}

void Heap_Sort(int arr[], int brr[]) {
int flag = 0;
for (int i = N; i > 0; --i) {
make_heap(arr, arr + i);
if (flag) {
cout << "Heap Sort" << endl << arr[0];
for (int i = 1; i < N; ++i)
cout << " " << arr[i];
}
if (equal(arr, arr + N, brr))
flag = 1;
swap(arr[0], arr[i - 1]);
}
}

int main() {
cin >> N;
int arr1[100], arr2[100], brr[100];
for (int i = 0; i < N; ++i) {
cin >> arr1[i];
arr2[i] = arr1[i];
}
for (int i = 0; i < N; ++i)
cin >> brr[i];
Insertion_Sort(arr1, brr);
Heap_Sort(arr2, brr);
return 0;
}



10-14 5121

07-31 5416
01-10
08-22 43万+
06-23 561
03-28 1397
06-17 9023
09-04 532
09-25 438
07-31 9512
05-24 1万+
11-27 202
05-18 1234