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[] x, int k, int n)
    To restore the max-heap condition when a node's priority is decreased.
    static void
    siftDown(float[] x, int k, int n)
    To restore the max-heap condition when a node's priority is decreased.
    static void
    siftDown(int[] x, 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[] x, int k, int n)
    To restore the max-heap condition when a node's priority is decreased.
    static void
    siftUp(double[] x, int k)
    To restore the max-heap condition when a node's priority is increased.
    static void
    siftUp(float[] x, int k)
    To restore the max-heap condition when a node's priority is increased.
    static void
    siftUp(int[] x, int k)
    To restore the max-heap condition when a node's priority is increased.
    static <T extends Comparable<? super T>>
    void
    siftUp(T[] x, int k)
    To restore the max-heap condition when a node's priority is increased.
    static void
    swap(double[] x, int i, int j)
    Swap two positions.
    static void
    swap(float[] x, int i, int j)
    Swap two positions.
    static void
    swap(int[] x, int i, int j)
    Swap two positions.
    static void
    swap(Object[] x, int i, int j)
    Swap two positions.
  • Method Details

    • swap

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

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

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

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

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

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

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

      static <T extends Comparable<? super T>> void siftUp(T[] x, int k)
      To restore the max-heap condition when a node's priority is increased. We move up the heap, exchaning the node at position k with its parent (at postion 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:
      x - the array.
      k - the index of array element.
    • siftDown

      static void siftDown(int[] x, 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:
      x - the array.
      k - the index of array element.
      n - the index n > k.
    • siftDown

      static void siftDown(float[] x, 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:
      x - the array.
      k - the index of array element.
      n - the index n > k.
    • siftDown

      static void siftDown(double[] x, 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:
      x - the array.
      k - the index of array element.
      n - the index n > k.
    • siftDown

      static <T extends Comparable<? super T>> void siftDown(T[] x, 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:
      x - the array.
      k - the index of array element.
      n - the index n > k.