Skip to content

Instantly share code, notes, and snippets.

@FrankHB
Created May 29, 2014 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankHB/8b64cc551ca607626d98 to your computer and use it in GitHub Desktop.
Save FrankHB/8b64cc551ca607626d98 to your computer and use it in GitHub Desktop.
李煌排序测试
#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