public class DutchNationalFlagSort<T extends java.lang.Comparable> extends java.lang.Object implements SortingEngine<T>
ARRAY_IS_EMPTY, DATA_TYPE_NOT_SUPPORTED_YET, DECIMAL_RADIX, DELIMITER_COMMA, ELEMENT_NOT_FOUND, LIST_IS_EMPTY, OPERATION_NOT_SUPPORTED_YET
Constructor and Description |
---|
DutchNationalFlagSort(T _red,
T _blue)
(white) is the implicit middle layer; i.e. |
DutchNationalFlagSort(T _red,
T _white,
T _blue)
|
Modifier and Type | Method and Description |
---|---|
void |
sort(T[] A)
Approach: |
ListNode<T> |
sortList(ListNode<T> list) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
checkArray, checkIntArray, checkList
public DutchNationalFlagSort(T _red, T _white, T _blue)
_red
- (red) : value of first group_white
- (white) : value of middle group_blue
- (blue) : value of third grouppublic void sort(T[] A)
There is just one check pointer 'w'. All steps depend on A[w]:
- swap with A[r] if it is red
- swap with A[b] if it is blue
- decrement w if it is
white.
The variables r and b indicate red and blue boundaries such that all elements to the
left of r are red and all elements to the right of b are blue.
It is clear that A swap
occurs when A[w] is red or blue.
sort
in interface SortingEngine<T extends java.lang.Comparable>