Skip to Content
Java Projects - Second Edition
book

Java Projects - Second Edition

by Peter Verhas
August 2018
Intermediate to advanced
524 pages
14h 45m
English
Packt Publishing
Content preview from Java Projects - Second Edition

Recursive sorting

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

package packt.java189fundamentals.ch03.qsort; // ... imports are deleted from print ... public class Qsort<E> { final private Comparator<E> comparator; final private Swapper swapper; // ... constructor setting fields deleted from print ... public void qsort(Sortable<E> sortable, int start, int end) { if (start < end) { final var pivot = sortable.get(start); final var partitioner = new Partitioner<E>(comparator, swapper); var cutIndex = partitioner.partition(sortable, start, end, pivot); if (cutIndex == start) { cutIndex++; } qsort(sortable, start, cutIndex - 1); qsort(sortable, cutIndex, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java 11 Cookbook - Second Edition

Java 11 Cookbook - Second Edition

Nick Samoylov, Mohamed Sanaulla

Publisher Resources

ISBN: 9781789131895Supplemental Content