469,908 Members | 2,213 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,908 developers. It's quick & easy.

How can I sort an array?

How can I sort an array so that the highest value has the index of 0 ?

I mean if i have a double array like this:

{ 0.1, 0.5, 0.32, 0.9 }

it should be transformed into a new array that looks like the
following::

{ 0.9, 0.5, 0.32, 0.1 }
Thanks in advance!
Nov 15 '05 #1
2 3492
Tobias Froehlich <re*******@gmx.net> wrote:
How can I sort an array so that the highest value has the index of 0 ?

I mean if i have a double array like this:

{ 0.1, 0.5, 0.32, 0.9 }

it should be transformed into a new array that looks like the
following::

{ 0.9, 0.5, 0.32, 0.1 }


Either use Array.Sort and then reverse it from the increasing order
you'll get out of it, or use Array.Sort and specify the comparator to
use. The former *may* be significantly faster for large arrays, as the
framework could optimise sorting arrays of primitives so that they
didn't need to be boxed/unboxed for each comparison.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Thanks, i'll try it out.

How fast it works is not an issue since it is for an array with only
10 entries.
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by its me | last post: by
4 posts views Thread by Brett | last post: by
40 posts views Thread by Elijah Bailey | last post: by
7 posts views Thread by ritchie | last post: by
21 posts views Thread by yeti349 | last post: by
5 posts views Thread by Jan Smith | last post: by
1 post views Thread by Marcus Kwok | last post: by
48 posts views Thread by Alex Chudnovsky | last post: by
4 posts views Thread by Santosh Nayak | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.