冒泡排序法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 冒泡排序
{
    class Program
    {
        static void bubble_sort(int[] unsorted)
        {
            for (int i = 0; i < unsorted.Length; i++)
            {
                for (int j = i; j < unsorted.Length; j++)
                {
                    if (unsorted[i] > unsorted[j])
                    {
                        int temp = unsorted[i];

                        unsorted[i] = unsorted[j];

                        unsorted[j] = temp;
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            int[] x = { 6, 2, 4, 1, 5, 9 };

            bubble_sort(x);

            foreach (var item in x)
            {
                Console.WriteLine(item);
            }
            Console.ReadLine();
        }
    }
}

  

 

posted @ 2015-08-10 00:48  人走茶亦凉  阅读(251)  评论(0编辑  收藏  举报