码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序法

时间:2015-08-10 01:40:42      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

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();
        }
    }
}

  

 

冒泡排序法

标签:

原文地址:http://www.cnblogs.com/hanke123/p/4716822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!