如题:输入5个人的成绩 然后自定义方法排序。。

解决方案 »

  1.   

    为什么不选择系统提供的。
    Array.Sort(你的数组);
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace Text
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] count = new int[5];  //  需要排序的数组
                int i, j;                  //  循环变量
                int temp;                  //   临时变量            // 读入数组
                Console.WriteLine("请输入5个数:");
                for (i = 0; i < 5; i++)
                {
                    Console.WriteLine("输入第{0}个数:",i+1);
                    count[i] = int.Parse(Console.ReadLine());  //  类型转换            }
                // 开始排序 -----------冒泡排序
                for (i = 0; i < count.Length-1; i++)   // 控制比较多少轮
                {
                    // 将最大的元素交换到最后
                    for (j = 0; j < count.Length-1-i; j++)
                    {
                        if(count[j] > count[j+1])
                        {
                            //  交换元素
                            temp = count[j];
                            count[j] = count[j + 1];
                            count[j + 1] = temp;
                        }
                    }
                }
                //  排序后输出
                Console.WriteLine("排序后:");
                for (i = 0; i < count.Length; i++)
                {
                    Console.WriteLine("{0}\t",count[i]);
                }
                Console.ReadLine();
            }
        }
    }
      

  3.   

     static void Main(string[] args)
            {            
               int[] count = new int[5];  //  需要排序的数组
                Console.WriteLine("请输入5个数:");
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine("输入第{0}个数:", i + 1);
                    count[i] = int.Parse(Console.ReadLine());  //  类型转换            }
                // 开始排序 -----------冒泡排序方法
                NewMethod1(ref count);
                //  排序后输出
               
                for (int i = 0; i < count.Length; i++)
                {
                    Console.WriteLine("{0}\t", count[i]);
                }
                       } 
    private static void NewMethod1(ref int[] count)
            {
                int temp;
                for (int i = 0; i < count.Length - 1; i++)   // 控制比较多少轮
                {
                    // 将最大的元素交换到最后
                    for (int j = 0; j < count.Length - 1 - i; j++)
                    {
                        if (count[j] > count[j + 1])
                        {
                            //  交换元素
                            temp = count[j];
                            count[j] = count[j + 1];
                            count[j + 1] = temp;
                        }
                    }
                }
            }
      

  4.   


    class MyArray{
       public string mySort(string[] oldStr){
          string[] resultStr=String.Empty;
          // 开始排序 ----laoas兄的代码-------冒泡排序
           return resultStr;
       }
    }MyArray arrSort = ne MyArray();
    arrSort.mySort(需要排序的字符串数组);
      

  5.   

    谢谢了 ,原来我自己调用方法的时候ref 后面跟的数组,
      初学 还不太会用,