namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
int[] array = { 43, 69, 11, 72, 28, 21, 56, 80, 48, 94, 32, 8 };
BubbleSort(array);
ShowSord(array);
Console.ReadKey();
}
private static void ShowSord(int[] array)
{
foreach (var num in array)
{
Console.Write($"{num} ");
}
Console.WriteLine();
}
public static void BubbleSort(int[] array)
{
for (int i=0;i<array.Length;i++)
{
int tempindex = i;
for (int j=i+1;j< array.Length; j++)
{
if (array[tempindex]> array[j])
{
tempindex = j;
}
}
if (tempindex!=i)
{
int tempValue = array[tempindex];
array[tempindex] = array[i];
array[i] = tempValue;
}
}
}
}
}
输出:
|
请发表评论