O'Reilly logo

Java 9 Programming By Example by Peter Verhas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recursive sorting

We will implement the quick sort with an extra class that is in the qsort package along with the partitioning class, which is as follows:

package packt.java9.by.example.ch03.qsort; // imports deleted from the print public class Qsort<E>  { // constructor injected final fields deleted from the print     public void qsort(SortableCollection<E> sortable, int start, int end) {         if (start < end) {             final E pivot = sortable.get(start);             final Partitioner<E> partitioner = new Partitioner<>(comparator, swapper);             int cutIndex = partitioner.partition(sortable, start, end, pivot);             if (cutIndex == start) {                 cutIndex++;             }             qsort(sortable, start, cutIndex - 1);             qsort(sortable, cutIndex, end);         }     } }

The method gets SortableCollection<E> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required