private static void Main( string [] args)
{
Vector[] vectors = GetVectors();
Console.WriteLine( string .Format( " n = {0} " , vectors.Length));
Stopwatch watch1 = new Stopwatch();
watch1.Start();
A(vectors);
watch1.Stop();
Console.WriteLine( " A sort time: " + watch1.Elapsed);
Print(vectors);
vectors = GetVectors();
watch1.Reset();
watch1.Start();
B(vectors);
watch1.Stop();
Console.WriteLine( " B sort time: " + watch1.Elapsed);
Print(vectors);
vectors = GetVectors();
watch1.Reset();
watch1.Start();
C(vectors);
watch1.Stop();
Console.WriteLine( " C sort time: " + watch1.Elapsed);
Print(vectors);
vectors = GetVectors();
watch1.Reset();
watch1.Start();
D(vectors);
watch1.Stop();
Console.WriteLine( " D sort time: " + watch1.Elapsed);
Print(vectors);
Console.ReadKey();
}
private static Vector[] GetVectors()
{
int n = 1 << 21 ;
Vector[] vectors = new Vector[n];
Random random = new Random();
for ( int i = 0 ; i < n; i ++ )
{
vectors[i] = new Vector();
vectors[i].X = random.NextDouble();
vectors[i].Y = random.NextDouble();
vectors[i].Z = random.NextDouble();
vectors[i].W = random.NextDouble();
}
return vectors;
}
private static void A(Vector[] vectors)
{
Array.Sort(vectors, new VectorComparer());
}
private static void B(Vector[] vectors)
{
int n = vectors.Length;
for ( int i = 0 ; i < n; i ++ )
{
Vector c1 = vectors[i];
c1.T = Math.Sqrt(Math.Pow(c1.X, 2 )
+ Math.Pow(c1.Y, 2 )
+ Math.Pow(c1.Z, 2 )
+ Math.Pow(c1.W, 2 ));
}
2011年上半年軟考報名時間及方式匯總軟考軟件設(shè)計師歷年真題匯總(2007年-2010年)
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |