First, define the swap method used in the sorting process to exchange the values of two integers:
/// <Summary>
/// Exchange the values of two integers
/// </Summary>
/// <Param name = "AA"> count 1 </param>
/// <Param name = "BB"> count 2 </param>
Private Static void swap (ref int AA, ref int bb)
{
Int temp;
Temp = BB;
BB = AA;
AA = temp;
}
// Bubble sort
Class Program
{
Static void main (string [] ARGs)
{
Int [] A = {1, 2, 5, 7, 9, 8, 10, 6, 4, 3 };
Bubblesort ();
For (INT I = 0; I <A. length; I ++)
Console. Write (A [I] + "");
Console. readkey ();
}
/// <Summary>
/// Bubble sort
/// </Summary>
/// <Param name = "A"> input the array to be sorted </param>
Private Static void bubblesort (INT [])
{
For (INT I = 0; I <A. Length-1; I ++)
{
For (Int J = 0; j <A. Length-I-1; j ++)
{
If (A [J] <A [J + 1]) // sort in descending order
{
Swap (Ref A [J], Ref A [J + 1]);
}
}
}
}
}
// Select sorting
Class Program
{
Static void main (string [] ARGs)
{
Int [] A = {1, 2, 4, 3, 6, 5, 7, 9, 8 };
Selectionsort ();
For (INT I = 0; I <A. length; I ++)
Console. Write (A [I] + "");
Console. readkey ();
}
/// <Summary>
/// Select sorting
/// </Summary>
/// <Param name = "A"> input the array to be sorted </param>
Private Static void selectionsort (INT [])
{
Int K;
For (INT I = 0; I <A. Length-1; I ++)
{
K = I;
For (Int J = I + 1; j <A. length; j ++)
{
If (A [J] <A [k]) // sort in ascending order
{
K = J;
}
}
If (K! = I)
Swap (Ref A [I], Ref A [k]);
}
}
}