您的位置:首页 > 其它

第一篇 博客 记录一个自己写的性能超级差的方法 以后想办法找出原因

2011-06-13 18:21 711 查看
public static void QuickSort<T>(int sta, int end, List<T> rows, Func<List<T>,int ,int, bool> comp)
{
if (sta > end)
{ return; }
int temp;

//第一次交换
int temp3 = new Random().Next(sta, end);
T x0;
x0 = rows[sta];
rows[sta] = rows[temp3];
rows[temp3] = x0;
temp = sta;

for (int i = sta + 1; i <= end; i++)
{
if (comp(rows,i,sta))
{
//第二次交换
int temp2 = ++temp;
T x;
x = rows[temp2];
rows[temp2] = rows[i];
rows[i] = x;
}
}
//第三次交换
T x2;
x2 = rows[sta];
rows[sta] = rows[temp];
rows[temp] = x2;

QuickSort(sta, temp - 1, rows, comp);
QuickSort(temp + 1, end, rows, comp);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐