1. Under C # code:
Using System;
Namespace ConsoleApplication1
{
Class Program
{
static void Main ()
{
int[] Arrsort = new int[] {10, 8, 3, 5, 6, 7, 9};//Initialize sort data
Bubble_sort (ref arrsort);//Call bubble Sort method
for (int i = 0; i < arrsort.length; i++)//Output sort result
{
Console.WriteLine ("The result of sorting is: {0}", Arrsort[i]);
}
Console.ReadLine ();//Pause Output Window
}
<summary>
C # implements a simple bubble sort
</summary>
private static void Bubble_sort (ref int[] Arrsort)//ref represents a reference type
{
int temp;//A pre-defined intermediate variable
for (int i = 0; i < arrsort.length; i++)
{
for (int j = i + 1; j < Arrsort.length; J + +)
{
if (Arrsort[j] < arrsort[i])//Exchange data location
{
temp = Arrsort[j];
ARRSORT[J] = Arrsort[i];
Arrsort[i] = temp;
}
}
}
}
}
}
2, the result of the output is as follows:
C # implements a simple bubble sort