关于排序

基础排序,大神请路过

冒泡排序:

class Program

         {

            //冒泡排序,从小到大

            static void Main(string[] args)

            {

                int[] Arr = { 3242, 6, 54324, 9, 10 };

                for (int i = 0; i < Arr.Length; i++)

                {

                    int k = 0;

                    for (int j = 0; j < Arr.Length; j++)

                    {

                        if (Arr[i] < Arr[j])

                        {

                            k = Arr[i];

                            Arr[i] = Arr[j];

                            Arr[j] = k;

                        }

                    }

                }

                for (int i = 0; i < Arr.Length; i++)

                {

                    Console.WriteLine(Arr[i] + "\n");

                }

                Console.ReadLine();

            }

        }

 

 

快速排序:

Static  Viod Main(stirng[] args)

{

   Int [] arry={10, 25, 9, 56, 2, 48};

QuSort(arry, 0 ,5);

For(int i=0; i<arr.length; i++)

{

  Console.Write(arr[i]);

}

Console.Write();

}

Public  static  QuSort (int [] arr ,int low, int hing )

{

//10  25  9  56  2  48

If(!low<hing)

{

  Return;

}

     Int i=low; int j=hing; temp=arr[low];

     While(i<j){

   While(low<hing&&temp<arr[j])

{

   j--;

}

If(i<j&&tmep>=arr[j])

{

   Arr[i]=arrr[j];

   i++;

}

While (i<j&&temp>arr[i])

{

   I++;

}

If(i<j&&temp<=arr[i])

{

  Arr[j]=arr[i];

  J--;

}

}

Arr[i]=temp;

QuSort(arr,low,i-1);

QuSort(arr,i+1,hing);

}

posted on 2018-05-07 09:18  编程流氓  阅读(75)  评论(0编辑  收藏  举报

导航