SiroKuro #5853(2008/02/27 03:39 GMT) [ C# ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
using System; using System.Collections.Generic; static class Program { static void Main(String[] args) { List<Pair> plist = new List<Pair>(); Random rand = new Random(); for(int i = 0; i < 10; i++) plist.Add(new Pair(rand.Next(5), rand.Next(5))); Console.WriteLine("----- 元データ"); foreach(Pair p in plist) Console.WriteLine(p); Console.WriteLine("----- 辞書順でソート"); plist.Sort(delegate(Pair p1, Pair p2) { return p1.x != p2.x ? p1.x.CompareTo(p2.x) : p1.y.CompareTo(p2.y); }); foreach(Pair p in plist) Console.WriteLine(p); Console.WriteLine("----- 距離順でソート"); plist.Sort(delegate(Pair p1, Pair p2) { return (p1.x * p1.x + p1.y * p1.y).CompareTo(p2.x * p2.x + p2.y * p2.y); }); foreach(Pair p in plist) Console.WriteLine(p); } } class Pair { public readonly int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } public override string ToString() { return "(" + x + ", " + y + ")"; } }
Rating0/0=0.00-0+
[ reply ]
SiroKuro
#5853()
[
C#
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]