案例:找1000000个数中最大的100个。
实现思路:
1.将1000000个数分成100组。
2.把每组中最大的数放在当前组的第一个位置。
3.对所有组最大数进行排序,相当于对组进行排序,生成新的list数组。
4.在list头组中找出第2大的数,从list末尾比较插入适当的位置。`
using System;
using System.Collections;
using System.Collections.Generic;
public class RankSort
{
public delegate bool Comparer(T t1, T t2);
private static Group[] indexs;
private int groupCount;
private T maxValue;
private int curIndex;
private int maxIndex;
private struct Group
{
public Group(int i, int s, int l)
{
startIndex = s;
length = l;
}
public int startIndex;
public int length;
}
/// <summary>
/// 对最大值排序
/// </summary>
/// <param name="arr"></param>
private void Sort(Group[] arr, T[] datas, Comparer action