Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1175
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Fri, 30 Sep 2011 18:58:24 -0500 |
| Date | Fri, 30 Sep 2011 16:58:21 -0700 |
| From | Patricia Shanahan <pats@acm.org> |
| User-Agent | Mozilla/5.0 (Windows NT 5.2; WOW64; rv:7.0) Gecko/20110922 Thunderbird/7.0 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Reverse sorting an array |
| References | <8ea2add1-ce9c-423b-bdb8-92c461cf9c6d@5g2000yqo.googlegroups.com> <j64aek$23e$1@dont-email.me> <2b9bc8c9-d6de-431f-8753-fe9d400e9b1b@n36g2000yqb.googlegroups.com> <4ihc87545r018lbbk02ggp21abgngho21n@4ax.com> <7c66f3a8-c02b-4b5a-b62e-f0561378bfec@b6g2000vbz.googlegroups.com> |
| In-Reply-To | <7c66f3a8-c02b-4b5a-b62e-f0561378bfec@b6g2000vbz.googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Message-ID | <l9adnVQkX7s9yhvTnZ2dnUVZ_vydnZ2d@earthlink.com> (permalink) |
| Lines | 27 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 70.230.204.200 |
| X-Trace | sv3-jDp/1Q7XP+upeHqI6BPlFQ9z7LKbSEqWkfnp+pPfFVQCP8CmW8BCqfUPMkV6O/A/D269xN0wh71OjuR!RWPMTw6SBaANPUHn+kF4UEEdwY2ugP8IxNhECUW5jKcWURzXhHr9P0Q51E+wr5CLwg+7aKFOeSoe!fQ8wnnTPK7h9M47VFy/KRz3RtsMKr0ESfboqigtAvNg/Bbs= |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 2506 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:1175 |
Show key headers only | View raw
On 9/30/2011 4:27 PM, Fred wrote: > But I must be missing something obvious here - why does this print > zeroes? ... > printArray(positives, positivesIndex); > Arrays.sort(positives); > printArray(positives, positivesIndex); ... Arrays.sort without a specified fromIndex and toIndex sorts the entire array. I would expect to see (positives.length - positivesIndex) zero elements before the first positive element in the sorted array. Given the facts that you are reading a variable number of elements and you need to do reverse sorting, are you *sure* you should be working with int rather than Integer? If you used Integer, you could build up a List exactly the right length, avoiding any extra zero elements. You could use Collections.sort with the Collections.reverseOrder() comparator to directly sort them in descending order. The whole thing would be simpler. At least so far, you are not doing any arithmetic that would need int, and you don't have anywhere near enough elements for there to be a significant performance difference. Patricia
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 04:03 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-30 07:50 -0400
Re: Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 15:24 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-30 20:50 -0400
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-10-01 19:38 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-01 22:58 -0400
Re: Reverse sorting an array Lew <lewbloch@gmail.com> - 2011-10-01 20:21 -0700
Re: Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 15:31 -0700
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-09-30 15:45 -0700
Re: Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 16:27 -0700
Re: Reverse sorting an array Patricia Shanahan <pats@acm.org> - 2011-09-30 16:58 -0700
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-09-30 15:43 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-30 20:57 -0400
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-09-30 04:58 -0700
What qualifies as a constant ? (Was: Reverse sorting an array) Mayeul <mayeul.marguet@free.fr> - 2011-09-30 14:45 +0200
Re: What qualifies as a constant ? (Was: Reverse sorting an array) Lew <lewbloch@gmail.com> - 2011-09-30 07:39 -0700
Re: What qualifies as a constant ? (Was: Reverse sorting an array) Mayeul <mayeul.marguet@free.fr> - 2011-09-30 17:15 +0200
Re: What qualifies as a constant ? (Was: Reverse sorting an array) Lew <lewbloch@gmail.com> - 2011-09-30 08:42 -0700
csiph-web