Created
May 29, 2014 05:02
-
-
Save FrankHB/8b64cc551ca607626d98 to your computer and use it in GitHub Desktop.
李煌排序测试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ytest/timing.hpp> // https://github.com/FrankHB/YSLib/blob/master/YBase/include/ytest/timing.hpp | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
using namespace ytest::timing; | |
struct tr | |
{ | |
int a; | |
int value; | |
tr() | |
{ | |
a = 0; | |
} | |
}; | |
vector<tr> | |
LiHuang_Sort(vector<int>& a, int fanwei) | |
{ | |
int k = 0, i, j, temp = 0, h; | |
vector<tr> ne(fanwei + 1); | |
for(i = 0; i < ne.size(); i++) | |
{ | |
ne[i].a = 1; | |
ne[i].value = 0; | |
} | |
for(i = 0; i < a.size(); i++) | |
{ | |
h = a[i]; | |
if((ne[h].value == 0)) | |
{ | |
ne[h].value = a[i]; | |
} | |
else | |
{ | |
ne[h].a = (ne[h].a) + 1; | |
} | |
} | |
return ne; | |
} | |
int | |
main() | |
{ | |
vector<int> c(10000000); | |
iota(c.begin(), c.end(), 0); | |
random_shuffle(c.begin(), c.end()); | |
auto a(c); | |
cout << "STL排序用时: " << once_c([&] {sort(c.begin(), c.end());}) * 1e3 << "ms" << endl; | |
cout << "李煌排序用时: " << once_c([&] {LiHuang_Sort(a, a.size());}) * 1e3 << "ms" << endl; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment