2 回答
TA贡献1757条经验 获得超8个赞
由于您似乎不关心排序算法本身,因此您可以迭代元组并将排序卸载到排序列表,如下所示:
对数字元组列表进行排序
using System;
using System.Collections.Generic;
namespace ConsoleApp
{
public class Program
{
static void Main(string[] args)
{
List<Tuple<double, int, int>> FHM = new List<Tuple<double, int, int>>();
FHM.Add(Tuple.Create(2500.00, 1, 5));
FHM.Add(Tuple.Create(2400.00, 2, 300));
FHM.Add(Tuple.Create(2300.00, 4, 10));
FHM.Add(Tuple.Create(2600.00, 1, 325));
var sorted = new SortedList<double, Tuple<double, int, int>>();
foreach (Tuple<double, int, int> t in FHM)
{
sorted.Add(t.Item1, t);
}
}
}
}
TA贡献1811条经验 获得超5个赞
var S2 = Stopwatch.StartNew();
var temp = Tuple.Create(0.00, 0, 0);
for (int i = 0; i < FHM.Count; i++)
{
for (int n = 0; n < i; n++)
{
if (FHM[n].Item1 > FHM[i].Item1)
{
temp = FHM[i];
FHM[i] = FHM[n];
FHM[n] = temp;
}
}
}
S2.Stop();
Console.WriteLine("Ticks S2 ForLoop = " + S2.ElapsedTicks); // 4000 ElapsedTicks
S2.Reset();
S2.Start();
FHM.Sort();
S2.Stop();
Console.WriteLine("Ticks S2 List.Sort(); = " + S2.ElapsedTicks); // 700000 ElapsedTicks
- 2 回答
- 0 关注
- 74 浏览
添加回答
举报