排序算法-冒泡排序

Posted RONGWEIJUN

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排序算法-冒泡排序相关的知识,希望对你有一定的参考价值。

 

 实现:

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

 

以上是关于排序算法-冒泡排序的主要内容,如果未能解决你的问题,请参考以下文章

排序算法之冒泡选择插入排序(Java)

排序算法_冒泡排序(算法设计与C代码实现)

三大基础排序算法(冒泡排序,选择排序,插入排序)

交换排序(冒泡排序快速排序的算法思想及代码实现)

冒泡排序

冒泡排序算法原理和代码实现,就是这么简单。。。