Course:: Easy-To-Follow Java Programming
Course:: Easy-To-Follow Java Programming
… that something makes you feel pain (slang for sore thing)
Insertion sort
Discount sort
Bubble sort
Champagne sort
Dual-Pivot Quicksort
Java has only solution for sorting numbers. You have to create your
own version of the sorting algorithm in which you can sort objects.
You have to transform each object to -1, 0 or +1, and then you can
compare them.
The methods return true if the ”left” object is smaller and false
otherwise.
The methods return nothing – they reorder the elements in the array
or collection.
7. What can you do if you have to make a program that sorts books
based on length (page number) and price based on user selection?
I create two Comparator’s, each one for one of the sorting key.
I implement one of the sorting keys and pray that the user will not
recognize the defect
The answers
… that something makes you feel pain (slang for sore thing)
Insertion sort
X Discount sort
Bubble sort
X Champagne sort
Dual-Pivot Quicksort
4. How can you tell Java how to compare objects (e.g. Fruit objects)?
Java has only solution for sorting numbers. You have to create your
own version of the sorting algorithm in which you can sort objects.
The methods return true if the ”left” object is smaller and false
otherwise.
The methods return nothing – they reorder the elements in the array
or collection.
X I create two Comparator’s, each one for one of the sorting key.
I implement one of the sorting keys and pray that the user will not
recognize the defect