Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Thursday, January 27, 2011

Sorting in array wihout using sort method

public static int[] SortArray(int[] characters, string Order)
{
if (Order == "Desc")
{
for (int i = 0; i < characters.Length; i++) { for (int j = i; j < characters.Length; j++) { if ((int)characters[j] > (int)characters[i])
{
int tempChar = characters[i];
characters[i] = characters[j];
characters[j] = tempChar;
}
}
}
}
else
{
for (int i = 0; i < characters.Length; i++)
{
for (int j = i; j < characters.Length; j++)
{
if ((int)characters[j] < (int)characters[i])
{
int tempChar = characters[i];
characters[i] = characters[j];
characters[j] = tempChar;
}
}
}
}
return characters;
}



///calling function

int[] characters = new int[] { 1,9,2,10,5 };
characters = Program.SortArray(characters, "Asc");
string str = "";
for (int i = 0; i < characters.Length; i++)
{
str += characters[i].ToString();
}
Console.WriteLine(str);
Console.ReadLine();