On Wed, 25 Jul 2012 15:21:54 +0200, Marcel Müller wrote:
> Is there a way to sort an IList<T> in place?
Sure, as long as it's not a read-only IList<T>. Of course there is.
Now, there's nothing in .NET that I know of that will do that. The built-in
sort implementations apply to arrays or List<T> instances. But there's
nothing stopping you from writing your own.
Indeed, it's possible that someone has already done so. The built-in .NET
sort algorithms use quicksort, which is great for many scenarios, but not
the most efficient in others. Even ignoring IList<T> there's good reason to
have alternatives, so in any case maybe it's already been done.
You should use your favorite web search engine to look for a third-party
library that does that. Even if it doesn't support IList<T> directly, with
an open-source library it would be easy enough to port the existing
algorithm to do so.
Heck...Arne seems to have lots of free time. Maybe he'll even write it for
you and post it here. :) It wouldn't even actually be that many lines of
code...it's just a matter of writing it down.
In the meantime, I recommend you take a look at these articles, with an eye
toward just writing it yourself:
http://en.wikipedia.org/wiki/Quicksort
http://en.wikipedia.org/wiki/Heapsort
Those are two of the best general-purpose sorts, both of which can be
implemented to be both memory- and time-efficient.
Pete