The ELEMENTS が 25 である代わりに、要素の大きな配列をランダムに生成する方法があります.... 10000、100000、または 1000000 要素であり、挿入ソート アルゴリズムを使用します。私は要素の大きな配列を持ち、挿入ソートを使用してそれらを並べ替え、次に逆順に並べようとしています。次に、time.h ファイルで clock() を使用して、各アルゴリズムの実行時間を計算しました。大量の数字でテストしようとしています。
#define ELEMENTS 25
void insertion_sort(int x[],int length);
void insertion_sort_reverse(int x[],int length);
int main()
{
clock_t tStart = clock();
int B[ELEMENTS]={4,2,5,6,1,3,17,14,67,45,32,66,88,
78,69,92,93,21,25,23,71,61,59,60,30};
int x;
cout<<"Not Sorted: "<<endl;
for(x=0;x<ELEMENTS;x++)
cout<<B[x]<<endl;
insertion_sort(B,ELEMENTS);
cout <<"Sorted Normal: "<<endl;
for(x=0;x<ELEMENTS;x++)
cout<< B[x] <<endl;
insertion_sort_reverse(B,ELEMENTS);
cout <<"Sorted Reverse: "<<endl;
for(x=0;x<ELEMENTS;x++)
cout<< B[x] <<endl;
double seconds = clock() / double(CLK_TCK);
cout << "This program has been running for " << seconds << " seconds." << endl;
system("pause");
return 0;
}