2017-04-12 104 views
0

我在网上找到了关于测量合并排序的执行时间的代码。我无法理解将数值放入数组的部分。在该行中:b [i] = i + 352; 352的价值是什么?如果我想要一个数组大小为2000,3000,4000等,下一个值是什么。(C++)合并排序执行时间

 int b[1000]; 
     int i; 
      for (i = 0; i < 1001; i++) { 
      b[i] = i + 352 ; 
      } //put values into array 

     int n = sizeof b/sizeof b[0]; 

     clock_t start = clock(); 
     merge_sort(b, n); 
     clock_t end = clock(); 

     double elapsed1 = ((end - start)/CLOCKS_PER_SEC);// seconds elapse 
     printf("Time elapsed for merge 1000: %f\n", elapsed1); 

回答

0

352仅仅是一个整数literal.It只是存储值i + 352 B [I]中,所以B [0]将具有值352,B [1]将具有值353等。如果您进一步将数组大小增加到2000,那么arr [1999]将包含1999 + 352。

计算任何程序的运行时间可能是这一个..
CMD/v一个更好的办法:“!!!!回波时间& youprogram.exe &回波时间”上/ C