主题:请教C#排序问题(急救啊!在线等!)
采用命令行参数输入15个整数,排序后按升序打印。(请好心人给点提示或者程序)
(用下面这个怎么改?)
using System;
using System.Collections;
namespace ArraySort
{
public class DataElement
{
public int value;
public DataElement() {}
public DataElement(int value) { this.value = value; }
}
public class DataElementComparer : IComparer
{
public int Compare(object x, object y)
{
return ((DataElement)x).value.CompareTo(((DataElement)y).value);
}
}
public class Client
{
public static void Main()
{
int[] myArray = {1,3,5,9,10,12,25,24,20};
DataElement[] d = new DataElement[9];
for (int i = 0; i < myArray.Length; i++)
d[i] = new DataElement(myArray[i]);
Console.WriteLine("排序前");
for (int i = 0;i < myArray.Length;i++)
{
Console.Write(d[i].value +",");
}
Array.Sort(d, new DataElementComparer());//排序实例化
Console.WriteLine("\n排序后");
for (int i = 0; i < myArray.Length; i++)
Console.Write(d[i].value + ", ");
Console.WriteLine();
}
}
}
(用下面这个怎么改?)
using System;
using System.Collections;
namespace ArraySort
{
public class DataElement
{
public int value;
public DataElement() {}
public DataElement(int value) { this.value = value; }
}
public class DataElementComparer : IComparer
{
public int Compare(object x, object y)
{
return ((DataElement)x).value.CompareTo(((DataElement)y).value);
}
}
public class Client
{
public static void Main()
{
int[] myArray = {1,3,5,9,10,12,25,24,20};
DataElement[] d = new DataElement[9];
for (int i = 0; i < myArray.Length; i++)
d[i] = new DataElement(myArray[i]);
Console.WriteLine("排序前");
for (int i = 0;i < myArray.Length;i++)
{
Console.Write(d[i].value +",");
}
Array.Sort(d, new DataElementComparer());//排序实例化
Console.WriteLine("\n排序后");
for (int i = 0; i < myArray.Length; i++)
Console.Write(d[i].value + ", ");
Console.WriteLine();
}
}
}