Which is why I said he may not have time to implement this now.
Piet Souris wrote: . . . lessons ahead of where Philip is. . . .
You can swap two elements in the strength array like thisor like this:-All you have to do to swap the other array is to run the same code in tandem;And you can double up the code in the 3‑version similarly. I shall add one line as a hint. Make sure to do the two swaps together so you have the same values for i and j.
Phillip O'Sullivan wrote: . . .
Thanks Piet ... but I don't know how to swap the corresponding names
Now, making a beer class implement Comparable is a little awkward. I can think of two ways to do it. One is to use the > operator. If you get the > the wrong way round, your array will sort backwards.There is a shorter way to write that with :? but you may not be familiar with :? yet.
I've started, so I'll finish.
For small arrays like yours with 10 elements, however, that isn't actually true. If you look up Arrays#sort (as in link in previous post of mine) you find it uses merge sort (or quicksort). For small arrays with less than about 50 elements, bubble‑sort is as fast or faster than the more sophisticated sorting algorithms.
A few moments ago, I wrote: . . . bubble‑sort is notoriously inefficient.
Campbell Ritchie wrote:Of course the most inefficient type of sorting is called Bogosort←Only to read over a drink. It has several other names: the bogo- bit is short for bogus.
Tushar Goel wrote:Just to be curious, i suppose for Java 7 onwards Arrays.sort doesn't use merge sort for objects. It uses now Tim Sort.
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.
public static void sort(Object a)
The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techiques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.
Tushar Goel wrote:Junilu, you are referring to the array of primitive type.
Campbell Ritchie wrote:If that is an IndoEuropean language, there is the possibility that the two words are etymologically related.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton