Code
using System;
using System.Collections.Generic;
using System.Text;
namespace SortAlgorithm
{
class BubbleSort //冒泡排序
{
static void Main1(string[] args)
{
int[] A ={ 10, 1, 2, 12, 34, 23, 56, 67, 4, 11 }; //基本思想:第一轮比较,把最大数弄到最后,其实现是所有的数依次交换
Bubble(A);
foreach (int k in A)
{
Console.Write(k + " ");
}
Console.Read();
}
private static void Bubble(int[] data)
{
int temp;
for (int i = 0; i < data.Length; i++)
{
for (int j = 0; j < data.Length - 1 - i; j++)
{
if (data[j] > data[j + 1])
{
temp = data[j];
data[j] = data[j + 1]; ;
data[j + 1] = temp;
}
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace SortAlgorithm
{
class BubbleSort //冒泡排序
{
static void Main1(string[] args)
{
int[] A ={ 10, 1, 2, 12, 34, 23, 56, 67, 4, 11 }; //基本思想:第一轮比较,把最大数弄到最后,其实现是所有的数依次交换
Bubble(A);
foreach (int k in A)
{
Console.Write(k + " ");
}
Console.Read();
}
private static void Bubble(int[] data)
{
int temp;
for (int i = 0; i < data.Length; i++)
{
for (int j = 0; j < data.Length - 1 - i; j++)
{
if (data[j] > data[j + 1])
{
temp = data[j];
data[j] = data[j + 1]; ;
data[j + 1] = temp;
}
}
}
}
}
}