insertion sort using c#
implement array sort using insertion sort
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted May 25, 2013, 7:57 AM
Below is a sample of implementation of Insertion sort for sorting the given names alphabetically. They could be more than ten also:
List
for (int pass = 1; pass <= Names.Count - 1; pass++)
{
for (int i = 1; i <= Names.Count - 1; i++)
{
string temp = Names[i];
for (int j = i - 1; j >= 0 && string.Compare(Names[j], temp, StringComparison.Ordinal) == 1; j--)
{
Names[j + 1] = Names[j];
Names[j] = temp;
}
}
}
Please don't forget to accept this as answer if it helps!
Thanks.