环球网校是美国纳斯达克上市企业欢聚时代(NASDAQ:YY)旗下品牌 | 住房和城乡建设部 建筑人才培训合作单位
您现在的位置在: > 计算机类 > 软件水平认证考试 > 考试辅导 >

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

2011-03-15 来源:互联网 作者:第一考试网

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); #

  // } #

  } #

 

#

责编: 返回顶部  打印

关于我们联系我们友情链接网站声明网站地图广告服务帮助中心