bitmap 排序:http://blog.csdn.net/xgdofull/archive/2010/03/28/5424611.aspx top k 算法:http://blog.donews.com/jiji262/2011/03/baidu_top_k_interview/
你可以尝试下 LINQ 的 OrderBy 和 Take,应该是为 top k 优化的。
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] array = new int[1000000]; for (int i = 0; i < 1000000; i++) { array[i] = i; } var top10 = array.AsParallel().OrderByDescending(x => x).Take(10); top10.ToList().ForEach(x => Console.WriteLine(x)); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] array = new int[1000000]; Random r = new Random(); for (int i = 0; i < 1000000; i++) { array[i] = r.Next(0, 2147483647); } var top10 = array.AsParallel().OrderByDescending(x => x).Take(10); top10.ToList().ForEach(x => Console.WriteLine(x)); } } }
top k 算法:http://blog.donews.com/jiji262/2011/03/baidu_top_k_interview/
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[1000000];
for (int i = 0; i < 1000000; i++)
{
array[i] = i;
}
var top10 = array.AsParallel().OrderByDescending(x => x).Take(10);
top10.ToList().ForEach(x => Console.WriteLine(x));
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[1000000];
Random r = new Random();
for (int i = 0; i < 1000000; i++)
{
array[i] = r.Next(0, 2147483647);
}
var top10 = array.AsParallel().OrderByDescending(x => x).Take(10);
top10.ToList().ForEach(x => Console.WriteLine(x));
}
}
}