⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atime.cpp

📁 data structures, algorithms and Application书的源代码
💻 CPP
字号:
// time heap sort

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include "hsort.h"

void main(void)
{
   int a[1001], n, i, step = 10;
   long counter;
   float seconds;
   clock_t start, finish;
   randomize();
   for (n = 10; n <= 1000; n += step)
   {// get time for size n
     start = clock( ); counter = 0;
     while (clock( ) - start < 10 || counter < 100) {
       counter++;
       for (i = 1; i <= n; i++)
          a[i] = rand(); // initialize 
       a[n] = INT_MAX;
       HeapSort(a, n);
     }
     finish = clock( );
     seconds = (finish - start) / CLK_TCK;
     cout << n << ' ' 
          << seconds / counter << endl;
     if (n == 100) step = 100;}
}

⌨️ 快捷键说明

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