这个程序得不到正确结果:
#region Using directivesusing System;
using System.Collections.Generic;
using System.Text;#endregionnamespace Specification
{
class Program
{
private static void Sort<T>(T[] data) where T : IComparable<T>
{
T temp;
for (int i = 0; i < data.Length; i++)
{
T t1 = data[i];
for (int j = i + 1; j < data.Length; j++)
{
T t2 = data[j];
if (t1.CompareTo(t2) < 0)
{
temp = t1;
t1 = t2;
t2 = temp;
}
}
Console.WriteLine("\n\n");
}
foreach (T t in data)
{
Console.WriteLine("{0}", t);
} } public static void Main(string[] args)
{
int[] a = new int[]{3,4,5,6,1};
char[] b = new char[] { 'a', 'b', 'd', 'e', 'c' };
Program.Sort(a);
Sort(b);
Console.ReadLine();
}
}
}
#region Using directivesusing System;
using System.Collections.Generic;
using System.Text;#endregionnamespace Specification
{
class Program
{
private static void Sort<T>(T[] data) where T : IComparable<T>
{
T temp;
for (int i = 0; i < data.Length; i++)
{
T t1 = data[i];
for (int j = i + 1; j < data.Length; j++)
{
T t2 = data[j];
if (t1.CompareTo(t2) < 0)
{
temp = t1;
t1 = t2;
t2 = temp;
}
}
Console.WriteLine("\n\n");
}
foreach (T t in data)
{
Console.WriteLine("{0}", t);
} } public static void Main(string[] args)
{
int[] a = new int[]{3,4,5,6,1};
char[] b = new char[] { 'a', 'b', 'd', 'e', 'c' };
Program.Sort(a);
Sort(b);
Console.ReadLine();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货