#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
void InsertSort(int* array, int n);
int main(){
clock_t start, end;
int n = 100000;
int array[n];
cout << "共" << n << "个数据" << endl;
for(int i = 0; i < n; i++){
array[i] = rand();
}
start = clock();
InsertSort(array, n);
end = clock();
/*
cout << "排序后" << endl;
for(int i = 0; i < n; i++){
cout << array[i] << endl;
}
*/
cout << "用时:" << (end - start) << "ms" << endl;
return 0;
}
void InsertSort(int* array, int n){
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
if(array[j] > array[i]){
std::swap(array[j], array[i]);
}
}
}
}
比冒泡排序快但是没有选择排序快