寫了一個關於冒泡的算法。
{
Console.Write("please input the number of variable:");
int num =Int32.Parse( Console.ReadLine());
int[] intArray=new int[num];
for (int i = 0; i < intArray.Length; i++)
{
Console.Write("please input the {0} variable:", i);
intArray[i] = Int32.Parse( Console.ReadLine());
}
intArray = Sort(intArray);
String output="";
for (int j = 0; j < intArray.Length; j++)
{
output += output.Equals("") ? intArray[j].ToString() : ","+intArray[j].ToString();
}
Console.WriteLine(output);
Console.ReadLine();
}
public static int[] Sort(int[] array)
{
for (int i = array.Length - 1; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (array[j] > array[i])
{
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
return array;
}
}
add by inkstone @2008年01月22日