Package smile.sort

# Interface Sort

public interface Sort
Sort algorithm trait that includes useful static functions such as swap and swift up/down used in many sorting algorithms.
• ## Method Summary

Static Methods
Modifier and Type
Method
Description
`static void`
```siftDown(double[] a, int k, int n)```
To restore the max-heap condition when a node's priority is decreased.
`static void`
```siftDown(float[] a, int k, int n)```
To restore the max-heap condition when a node's priority is decreased.
`static void`
```siftDown(int[] a, int k, int n)```
To restore the max-heap condition when a node's priority is decreased.
`static <T extends Comparable<? super T>>void`
```siftDown(T[] a, int k, int n)```
To restore the max-heap condition when a node's priority is decreased.
`static void`
```siftUp(double[] a, int k)```
To restore the max-heap condition when a node's priority is increased.
`static void`
```siftUp(float[] a, int k)```
To restore the max-heap condition when a node's priority is increased.
`static void`
```siftUp(int[] a, int k)```
To restore the max-heap condition when a node's priority is increased.
`static <T extends Comparable<? super T>>void`
```siftUp(T[] a, int k)```
To restore the max-heap condition when a node's priority is increased.
`static void`
```swap(double[] a, int i, int j)```
Swap two positions.
`static void`
```swap(float[] a, int i, int j)```
Swap two positions.
`static void`
```swap(int[] a, int i, int j)```
Swap two positions.
`static void`
```swap(Object[] a, int i, int j)```
Swap two positions.
• ## Method Details

• ### swap

static void swap(int[] a, int i, int j)
Swap two positions.
Parameters:
`a` - the array.
`i` - the index of array element.
`j` - the index of other element.
• ### swap

static void swap(float[] a, int i, int j)
Swap two positions.
Parameters:
`a` - the array.
`i` - the index of array element.
`j` - the index of other element.
• ### swap

static void swap(double[] a, int i, int j)
Swap two positions.
Parameters:
`a` - the array.
`i` - the index of array element.
`j` - the index of other element.
• ### swap

static void swap(Object[] a, int i, int j)
Swap two positions.
Parameters:
`a` - the array.
`i` - the index of array element.
`j` - the index of other element.
• ### siftUp

static void siftUp(int[] a, int k)
To restore the max-heap condition when a node's priority is increased. We move up the heap, exchanging the node at position k with its parent (at position k/2) if necessary, continuing as long as `a[k/2] < a[k]` or until we reach the top of the heap.
Parameters:
`a` - the array.
`k` - the index of array element.
• ### siftUp

static void siftUp(float[] a, int k)
To restore the max-heap condition when a node's priority is increased. We move up the heap, exchanging the node at position k with its parent (at position k/2) if necessary, continuing as long as `a[k/2] < a[k]` or until we reach the top of the heap.
Parameters:
`a` - the array.
`k` - the index of array element.
• ### siftUp

static void siftUp(double[] a, int k)
To restore the max-heap condition when a node's priority is increased. We move up the heap, exchanging the node at position k with its parent (at position k/2) if necessary, continuing as long as `a[k/2] < a[k]` or until we reach the top of the heap.
Parameters:
`a` - the array.
`k` - the index of array element.
• ### siftUp

static <T extends Comparable<? super T>> void siftUp(T[] a, int k)
To restore the max-heap condition when a node's priority is increased. We move up the heap, exchanging the node at position k with its parent (at position k/2) if necessary, continuing as long as `a[k/2] < a[k]` or until we reach the top of the heap.
Type Parameters:
`T` - the data type of array elements.
Parameters:
`a` - the array.
`k` - the index of array element.
• ### siftDown

static void siftDown(int[] a, int k, int n)
To restore the max-heap condition when a node's priority is decreased. We move down the heap, exchanging the node at position k with the larger of that node's two children if necessary and stopping when the node at k is not smaller than either child or the bottom is reached. Note that if n is even and k is n/2, then the node at k has only one child -- this case must be treated properly.
Parameters:
`a` - the array.
`k` - the index of array element.
`n` - the index `n > k`.
• ### siftDown

static void siftDown(float[] a, int k, int n)
To restore the max-heap condition when a node's priority is decreased. We move down the heap, exchanging the node at position k with the larger of that node's two children if necessary and stopping when the node at k is not smaller than either child or the bottom is reached. Note that if n is even and k is n/2, then the node at k has only one child -- this case must be treated properly.
Parameters:
`a` - the array.
`k` - the index of array element.
`n` - the index `n > k`.
• ### siftDown

static void siftDown(double[] a, int k, int n)
To restore the max-heap condition when a node's priority is decreased. We move down the heap, exchanging the node at position k with the larger of that node's two children if necessary and stopping when the node at k is not smaller than either child or the bottom is reached. Note that if n is even and k is n/2, then the node at k has only one child -- this case must be treated properly.
Parameters:
`a` - the array.
`k` - the index of array element.
`n` - the index `n > k`.
• ### siftDown

static <T extends Comparable<? super T>> void siftDown(T[] a, int k, int n)
To restore the max-heap condition when a node's priority is decreased. We move down the heap, exchanging the node at position k with the larger of that node's two children if necessary and stopping when the node at k is not smaller than either child or the bottom is reached. Note that if n is even and k is n/2, then the node at k has only one child -- this case must be treated properly.
Type Parameters:
`T` - the data type of array elements.
Parameters:
`a` - the array.
`k` - the index of array element.
`n` - the index `n > k`.