2011年软件设计师辅导:并行排序算法(5)

2011年软件设计师辅导:并行排序算法(5)
主函数及测试代码 在蛙蛙池塘 代码基础上修改
using System; #
using System.Collections.Generic;
using System.Diagnostics;
namespace Vector4Test
{
public class Vector
{
#
public double W;
public double X;
#
public double Y;
public double Z; #
public double T; #
}
internal class VectorComparer : IComparer < Vector > #
{
public int Compare(Vector c1, Vector c2) #
{
#
if (c1 == null || c2 == null ) #
throw new ArgumentNullException( " Both objects must not be null " );
#
double x = Math.Sqrt(Math.Pow(c1.X, 2 )
+ Math.Pow(c1.Y, 2 )
+ Math.Pow(c1.Z, 2 ) #
+ Math.Pow(c1.W, 2 )); #
double y = Math.Sqrt(Math.Pow(c2.X, 2 ) #
+ Math.Pow(c2.Y, 2 ) #
+ Math.Pow(c2.Z, 2 )
#
+ Math.Pow(c2.W, 2 ));
#
if (x > y)
#
return 1 ; #
else if (x < y)
return - 1 ; #
else
#
return 0 ;
} #
}
internal class VectorComparer2 : IComparer < Vector >
{ #
public int Compare(Vector c1, Vector c2)
{
#
if (c1 == null || c2 == null ) #
throw new ArgumentNullException( " Both objects must not be null " ); #
if (c1.T > c2.T)
#
return 1 ;
#
else if (c1.T < c2.T)
#
return - 1 ; #
else #
return 0 ; #
}
} #
internal class Program #
{ #
private static void Print(Vector[] vectors)
#
{ #
// foreach (Vector v in vectors)
#
// {
// Console.WriteLine(v.T); #
// } #
} #