没分,没动力啊!!难怪没人搭理你
从小到大的排序
class Program
{
public static void Sort(int[] myArray)
{
// 取长度最长的词组 -- 冒泡法
for (int j = 1; j < myArray.Length;j++)
{
for (int i = 0; i < myArray.Length - 1; i++)
{
// 如果 myArray[i] > myArray[i+1] ,则 myArray[i] 上浮一位
if (myArray[i] >myArray[i + 1])
{
int temp = myArray[i];
myArray[i] = myArray[i + 1];
myArray[i + 1] = temp;
}
}
}
}
static void Main(string[] args)
{
int[] myArray = new int[] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
Sort(myArray);
for (int m = 0; m < myArray.Length; m++)
{
Console.WriteLine(myArray[m]);
}
}
从大到小的排序
class Program
{
public static void Sort(int[] myArray)
{
// 取长度最长的词组 -- 冒泡法
for (int j = 1; j < myArray.Length;j++)
{
for (int i = 0; i < myArray.Length - 1; i++)
{
// 如果 myArray[i] < myArray[i+1] ,则 myArray[i] 下沉一位
if (myArray[i] < myArray[i + 1])
{
int temp = myArray[i];
myArray[i] = myArray[i + 1];
myArray[i + 1] = temp;
}
}
}
}
static void Main(string[] args)
{
int[] myArray = new int[] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
Sort(myArray);
for (int m = 0; m < myArray.Length; m++)
{
Console.WriteLine(myArray[m]);
}
}