小编Jos*_*hua的帖子

定时冒泡排序

我必须计算冒泡排序需要多长时间并打印所需的时间.在我的程序中,打印的时间总是0.00秒.谁能告诉我我做错了什么?

int main()
{
    srand((unsigned)time(NULL));
    int arr[5000], arr2[5000]; 
    int i;
    time_t start, end;
    double timeDiff;

    for(i=0; i < 5000; i++)
    {
        arr[i] = rand() % 100 + 1;
        arr2[i] = arr[i];
    }

    cout << "Here is the initial array:" << endl;
    printArray(arr, 5000);

    time(&start);
    bubbleSort(arr, 5000);
    time(&end);
    timeDiff = difftime(end, start);

    cout << "\nHere is the array after a bubble sort:" << endl;
    printArray(arr, 5000);
    cout << fixed << setprecision(2) << "\nIt took " << timeDiff << " seconds to …
Run Code Online (Sandbox Code Playgroud)

c sorting timing bubble-sort

1
推荐指数
1
解决办法
2697
查看次数

标签 统计

bubble-sort ×1

c ×1

sorting ×1

timing ×1