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);
// }
}
第一考试网友情提示:如果您遇到任何疑问,请登录第一考试网考试辅导频道或添加qq:,第一考试网以“为考友服务”为宗旨,秉承“快乐学习,轻松考试!”的理念,旨在为广大考友打造一个良好、温馨的学习与交流平台,欢迎持续关注。以上是小编为大家推荐的《2011年软件设计师辅导:并行排序算法(5)》相关信息。
编辑推荐