排序算法-冒泡排序
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; } } } } } }
以上是关于排序算法-冒泡排序的主要内容,如果未能解决你的问题,请参考以下文章