C# 实现 冒泡排序
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
/***
*
* 冒泡排序
*
*
* * **/
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
int[] array = {32,24 ,21,20,18,3,8,57};
BubbleSort(array);
foreach (int index in array)
{
Console.WriteLine(index + "\t");
}
}
public static void BubbleSort(int[] array)
{
int temp = 0;
for (int i = 0; i < array.Length - 1; i++)
{
for (int j = 0; j < array.Length - 1 - i; j++)
{
if (array[j] > array[j + 1])//如果前一个数比后一个数大,则交换
{
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
}
}
}
// 3,8,18,20,21,24,32,57
写的是不难,难的是天天坚持写!