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:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.