我一直在嘗試使用線程優化排序算法(快速排序)。我知道它在std :: sort()實現中已經相當不錯了,但我試圖通過對計算機進行優化來打敗它,並且同時瞭解線程。如何使用具有遞歸模板函數的線程
所以,我的問題是,我如何使用線程與我的遞歸快速排序功能?
這裏的功能(與不重要而最質疑的東西刪除):
template <typename T>
void quicksort(T arr[], const int &size, const int &beginning, const int &end)
{
// Algorithm here
thread t1(quicksort, arr, size, beginning, slow - 1);
thread t2(quicksort, arr, size, slow + 1, end);
}
如果我錯了,你最終需要更多的代碼,讓我知道,我會更新它。
我使用Visual Studio 2012,以及截至目前,該錯誤狀態:
error C2661: 'std::thread::thread' : no overloaded function takes 5 arguments
我也打過電話REF(ARR)等對每個參數的,但我得到了同樣的錯誤。
編輯: 由@mfontanini嘗試解決方法後,我可以沒有錯誤編譯,但上運行,我得到:
Debug Error!
Program: ...sktop\VisualStudio\Projects\SpeedTester\Debug\SpeedTester.exe
R6010
- abort() has been called
(Press Retry to debug the application)
重複了一個又一遍。最終,它與代碼退出3.
謝謝!這與@mfontanini得到我的代碼運行。並感謝您的額外信息!我一定記住它。 – Leonhart231 2013-02-24 18:36:55