Bubblesorta 要return arrayList;
或者public void Bubblesorta(ref int[] arrayList)这样声明

解决方案 »

  1.   

    temp = arrayList[i]; arrayList[i] = arrayList[i+1]; arrayList[i+1] = temp; 
      

  2.   


        public void Bubblesorta(ref int[] arrayList)
        {
            int i, j, temp;
            //bool temp; 
            for (j = 1; j <= arrayList.Length - 1; j++)
                for (i = 0; i < arrayList.Length - j; i++)
                    if (arrayList[i] > arrayList[i + 1])
                    {
                        temp = arrayList[i]; arrayList[i] = arrayList[i + 1]; arrayList[i] = temp;
                    }
        }
      

  3.   

    写程序要细心,格式也不注意,为什么不分开行写?
    public void Bubblesorta(int[] arrayList)
    {
    int i, j, temp;
    //bool temp; 
    for (j = 1; j <= arrayList.Length - 1; j++)
    {
    for (i = 0; i < arrayList.Length - j; i++)
    {
    if (arrayList[i] > arrayList[i + 1])
    {
    temp = arrayList[i]; 
    arrayList[i] = arrayList[i + 1];
    arrayList[i + 1] = temp;
    }
    }
    }
    }static void Main(string[] args)
    {
    int[] arr = new int[] { 1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47 };
    Program1 p = new Program1();
    p.Bubblesorta(arr);
    for (int m = 0; m < arr.Length; m++)
    Console.WriteLine("{0} ", arr[m]);
    Console.WriteLine();
    Console.ReadKey();
    }
      

  4.   

    不过呢,有现成的System.Array.Sort()方法可用,除非你想作排序练习:
    class Program 

      static void Main()
      { 
        int[] arr = { 1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47 }; 
        System.Array.Sort(arr); 
        foreach (int m in arr)
        { 
          System.Console.WriteLine(m); 
        }
      }