time1.cpp

来自「一本全面剖析C++数据结构算法的书籍」· C++ 代码 · 共 24 行

CPP
24
字号
// worst case insertion sort times// bad when times are small#include <iostream.h>#include <time.h>#include "insort.h"void main(void){   int a[1000], step = 10;   clock_t start, finish;   for (int n = 0; n <= 1000; n += step) {      // get time for size n      for (int i = 0; i < n; i++)         a[i] = n - i; // initialize      start = clock( );      InsertionSort(a, n);      finish = clock( );      cout << n << ' ' << (finish - start) / CLOCKS_PER_SEC << endl;      if (n == 100) step = 100;      }   }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?