开发者

Algorithm for ordering a set [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopene开发者_开发知识库d, visit the help center. Closed 11 years ago.

I have a set of 50 items and many conditions that specificy which element should come before other.

How to I create a ordered list?

Will like it in C# though can translate it from other languages.


Topological Sort


Translate the "many conditions" into a comparison function, and then use that in conjunction with a comparison-based sort (in the general case).

The best comparison-based sorting algorithms are O(nlogn) in the best case. Merge sort is one such algorithm and is pretty easy to implement... there are many others.

If your conditions constitute a partial ordering (rather than a total ordering), Topological sort might be most appropriate.


There are a number of sorting algorithms you can look into. The two that come to mind off the top of my head are the bubble sort and the quick sort.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜