Wednesday, March 26, 2008

Simple Sorting Using C# - Descending


public class Sort
{
public static void Main()
{
int[] iArr = { 9, 4, 2, 7, 6, 1, 0, 5, 3, 8 };
int i=0, j, temp;
for (i = 0; i < iArr.Length; i++)
{
for (j = i + 1; j < iArr.Length; j++)
{
if (iArr[i] < iArr[j]) // Descending
{
temp = iArr[i];
iArr[i] = iArr[j];
iArr[j] = temp;
}
} Console.WriteLine("iArr["+i+"] =>" + "{0}", iArr[i]);
}
Console.ReadLine();
}
}

No comments: