排序算法-冒泡排序

 

 实现:

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

namespace _006_冒泡排序
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] data = new int[] { 42, 20, 17,27,13,8,17,48 };
            BubbleSort(data);
            for (int i = 0; i < data.Length; i++)
            {
                Console.Write(data[i] + " ");
            }
        }

        static void BubbleSort(int[] dataArray)
        {
            for (int i = 0; i < dataArray.Length-1; i++)
            {
                for (int j = 0; j < dataArray.Length-i-1; j++)
                {
                    if (dataArray[j] > dataArray[j+1])
                    {
                        int temp = dataArray[j];
                        dataArray[j] = dataArray[j+1];
                        dataArray[j+1] = temp;
                    }
                }
            }
        }
    }
}

 

posted @ 2017-12-27 00:23  RONGWEIJUN  阅读(108)  评论(0编辑  收藏  举报