<summary>
Swaps the value of two integers
</summary>
<param name= "AA" > Number 1</param>
<param name= "BB" > Number 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 (a);
for (int i = 0; i < a.length; i++)
Console.Write (A[i] + "");
Console.readkey ();
}
<summary>
Bubble sort
</summary>
<param name= "A" > incoming array to sort </param>
private static void Bubblesort (int[] a)
{
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])//descending order
{
Swap (ref a[j], ref A[J + 1]);
}
}
}
}
}
Select sort
Class Program
{
static void Main (string[] args)
{
Int[] A = {1, 2, 4, 3,6,5,7,9,8};
Selectionsort (a);
for (int i = 0; i < a.length; i++)
Console.Write (A[i] + "");
Console.readkey ();
}
<summary>
Select sort
</summary>
<param name= "A" > incoming array to sort </param>
private static void Selectionsort (int[] a)
{
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])//ascending order
{
K = J;
}
}
if (k!=i)
Swap (ref a[i], ref a[k]);
}
}
}
--Excerpt from ZHOUHB
C # implements integer bubble sorting, select sort