How to sort array without using sort method in C# [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
开发者_开发问答Closed 9 years ago.
Improve this questionHow to sort array without using sort method in C#
Visualization and Comparison of sorting algorithms in C#
example code
public IList BubbleSort(IList arrayToSort)
{
int n = arrayToSort.Count - 1;
for (int i = 0; i < n; i++)
{
for (int j = n; j > i; j--)
{
if (((IComparable)arrayToSort[j - 1]).CompareTo(arrayToSort[j]) > 0)
{
object temp = arrayToSort[j - 1];
arrayToSort[j - 1] = arrayToSort[j];
arrayToSort[j] = temp;
}
}
}
return arrayToSort;
}
above will surely helps you to understand the thing you want
By assigning value by value in alphabetical or whatever order.
Sorry, but I don't get your question. What is the actual problem you are trying to solve?
Use nested loop sorting methods such as bubble sort.
But why would you want to do such a thing?
Since the array implements IEnumerable<T>
, you can use the OrderBy
extention method on IEnumerable
to sort it.
If your question is how to do it without using any built in functionality in the framework, I guess I will have to ask. Why??
精彩评论