开发者

How to sort array without using sort method in C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

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 question

How 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??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜