Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.help Subject: Re: How to sort String array A based on int array B Date: Fri, 23 Sep 2011 20:45:20 -0400 Organization: A noiseless patient Spider Lines: 39 Message-ID: References: <1k2n77ltdv7ml661pa9a2g63j8q5l1c66g@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 24 Sep 2011 00:45:54 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="f8igmItKsWs6nM5YanFxAA"; logging-data="1539"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0ghmcM7Rrtjt14JoyvQas" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Cancel-Lock: sha1:V5tTN0lWmv+4j5hOtFrGJPx4HkA= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:1124 On 9/23/2011 10:13 AM, Thee Chicago Wolf [MVP] wrote: > [...] > Yes, rank[k] is already sorted from most popular to least popular (1 > being most popular and 6 being least). artist [k] is scrambled (read: > unsorted) but *does* have its know rank preceding it (i.e., 6_ or 4_). > After all, how could you sort a bunch of Artists (read: String items) > without already knowing their current / existing ranking? To me that > doesn't seem possible. Or I just don't know how to do that (yet). ^_^ That's the crux of the homework problem. Given a telephone directory sorted by name, produce a directory sorted by number. Given a list of politicians' names and a corresponding list of the number of votes each received, produce a list ordered by vote count. Given a list of planet names and a list of their masses, produce a list ordered by mass. Various people have given you the broad outline. First, determine what governs the desired sort order: telephone number, vote count, planetary mass. This tells you which list is to be sorted, and which list is just to be carried along. Sort the chosen list with whatever technique you fancy, but each time you move an element of that list, move the corresponding element of the other list similarly. Back to the telephone directory: What influence does a person's name have on his final position in the list? None -- it's entirely determined by his phone number. He could go to court and have his name legally changed from Aaron Aardvark to Zuniga Zymanski, and his position in the sorted list would remain unaltered. Since his name does not affect the outcome (his phone number is the only thing that matters), no comparison of his name to any other name or to any other thing at all can affect the outcome. Therefore, his name need not enter into any comparisons; all the comparisons involve his phone number and only his phone number. I hope that's enough to get you started. -- Eric Sosman esosman@ieee-dot-org.invalid