Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1267
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Array sort problem. |
| Date | 2011-10-19 15:22 -0700 |
| Organization | Canadian Mind Products |
| Message-ID | <iaju97p2erv8ral5ql9ftum58uof9tkrt0@4ax.com> (permalink) |
| References | <j7i0eo$kfs$1@speranza.aioe.org> |
On Tue, 18 Oct 2011 03:42:18 +0800, Warren Tang <nospam@tangcs.com> wrote, quoted or indirectly quoted someone who said : >Hi,everyone > >I have an array: > >index value >0 33 >1 22 >2 44 >3 11 > >Now I'd like to sort it, but I also need to preserve the original index, >like this: > >newIndex originalIndex sortedValue >0 3 11 >1 1 22 >2 0 33 >3 2 44 > >How can this be done conveniently in Java? > >Regards, >Warren Tang This problem also occurs if your sort algorithm is not stable and you want a stable result. You have to add the original index to the objects you sort and use it as a tie-breaker. -- Roedy Green Canadian Mind Products http://mindprod.com It should not be considered an error when the user starts something already started or stops something already stopped. This applies to browsers, services, editors... It is inexcusable to punish the user by requiring some elaborate sequence to atone, e.g. open the task editor, find and kill some processes.
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar
Array sort problem. Warren Tang <nospam@tangcs.com> - 2011-10-18 03:42 +0800
Re: Array sort problem. "Alex Mentis" <foo@invalid.invalid> - 2011-10-17 21:14 +0000
Re: Array sort problem. Lew <lewbloch@gmail.com> - 2011-10-17 15:54 -0700
Re: Array sort problem. Warren Tang <nospam@tangcs.com> - 2011-10-19 10:59 +0800
Re: Array sort problem. Roedy Green <see_website@mindprod.com.invalid> - 2011-10-19 15:22 -0700
csiph-web