Codota Logo
smile.sort
Code IndexAdd Codota to your IDE (free)

How to use smile.sort

Best Java code snippets using smile.sort (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
BufferedReader b =
  • Codota IconInputStream in;new BufferedReader(new InputStreamReader(in))
  • Codota IconReader in;new BufferedReader(in)
  • Codota IconFile file;new BufferedReader(new FileReader(file))
  • Smart code suggestions by Codota
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending numerical order.
 * @return the original index of elements after sorting in range [0, n).
 */
public static int[] sort(int[] arr) {
  int[] order = new int[arr.length];
  for (int i = 0; i < order.length; i++) {
    order[i] = i;
  }
  sort(arr, order);
  return order;
}
origin: com.github.haifengl/smile-math

/**
 * Find the median of an array of type integer.
 */
public static int median(int[] a) {
  int k = a.length / 2;
  return select(a, k);
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending numerical order.
 */
public static void sort(int[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
  for (int i = n - 1; i > 0; i--) {
    SortUtils.swap(arr, 0, i);
    SortUtils.siftDown(arr, 0, i - 1);
  }
}
origin: com.github.haifengl/smile-math

/**
 * Removes and returns the index of item with minimum value (highest priority).
 */
public int poll() {
  swap(1, n);
  sink(1, n - 1);
  return pq[n--];
}
origin: com.github.haifengl/smile-math

/**
 * Find the third quantile (p = 3/4) of an array of type double. The input array will
 * be rearranged.
 */
public static <T extends Comparable<? super T>> T q3(T[] a) {
  return QuickSelect.q3(a);
}
origin: com.github.haifengl/smile-math

/**
 * fix up.
 */
private void swim(int k) {
  while (k > 1 && less(k, (k + d - 2) / d)) {
    swap(k, (k + d - 2) / d);
    k = (k + d - 2) / d;
  }
}
origin: com.github.haifengl/smile-math

/**
 * Reverses the order of the elements in the specified array.
 * @param a an array to reverse.
 */
public static void reverse(double[] a) {
  int i = 0, j = a.length - 1;
  while (i < j) {
    SortUtils.swap(a, i++, j--);  // code for swap not shown, but easy enough
  }
}
origin: com.github.haifengl/smile-math

/**
 * Place the array in max-heap order. Note that the array is not fully sorted.
 */
private static <T extends Comparable<? super T>> void heapify(T[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
}
origin: com.github.haifengl/smile-math

/**
 * Insert a new item into queue.
 * @param v the index of item.
 */
public void insert(int v) {
  pq[++n] = v;
  qp[v] = n;
  swim(n);
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending order.
 * @return the original index of elements after sorting in range [0, n).
 */
public static <T extends Comparable<? super T>>  int[] sort(T[] arr) {
  int[] order = new int[arr.length];
  for (int i = 0; i < order.length; i++) {
    order[i] = i;
  }
  sort(arr, order);
  return order;
}
origin: com.github.haifengl/smile-math

/**
 * Find the third quantile (p = 3/4) of an array of type float.
 */
public static float q3(float[] a) {
  int k = 3 * a.length / 4;
  return select(a, k);
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending numerical order.
 */
public static void sort(float[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
  for (int i = n - 1; i > 0; i--) {
    SortUtils.swap(arr, 0, i);
    SortUtils.siftDown(arr, 0, i - 1);
  }
}
origin: com.github.haifengl/smile-math

/**
 * 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] &lt; a[k] or
 * until we reach the top of the heap.
 */
public static void siftUp(float[] arr, int k) {
  while (k > 1 && arr[k/2] < arr[k]) {
    swap(arr, k, k/2);
    k = k/2;
  }
}
origin: com.github.haifengl/smile-math

/**
 * Besides sorting the array arr, the array brr will be also
 * rearranged as the same order of arr.
 */
public static void sort(int[] arr, Object[] brr) {
  sort(arr, brr, arr.length);
}
origin: com.github.haifengl/smile-math

/**
 * Find the median of an array of type double.
 */
public static double median(double[] a) {
  int k = a.length / 2;
  return select(a, k);
}
origin: com.github.haifengl/smile-math

/**
 * Reverses the order of the elements in the specified array.
 * @param a an array to reverse.
 */
public static <T> void reverse(T[] a) {
  int i = 0, j = a.length - 1;
  while (i < j) {
    SortUtils.swap(a, i++, j--);
  }
}
origin: com.github.haifengl/smile-math

/**
 * Besides sorting the array arr, the array brr will be also
 * rearranged as the same order of arr.
 */
public static void sort(float[] arr, Object[] brr) {
  sort(arr, brr, arr.length);
}
origin: com.github.haifengl/smile-math

/**
 * Find the third quantile (p = 3/4) of an array of type integer.
 */
public static int q3(int[] a) {
  int k = 3 * a.length / 4;
  return select(a, k);
}
origin: com.github.haifengl/smile-math

/**
 * This is an effecient implementation Quick Sort algorithm without
 * recursive. Besides sorting the array arr, the array brr will be also
 * rearranged as the same order of arr.
 */
public static void sort(double[] arr, double[] brr) {
  sort(arr, brr, arr.length);
}
origin: com.github.haifengl/smile-math

  /**
   * Find the third quantile (p = 3/4) of an array of type double.
   */
  public static <T extends Comparable<? super T>> T q3(T[] a) {
    int k = 3 * a.length / 4;
    return select(a, k);
  }
}
smile.sort

Most used classes

  • QuickSort
    Quicksort is a well-known sorting algorithm that, on average, makes O(n log n) comparisons to sort n
  • DoubleHeapSelect
    This class tracks the smallest values seen thus far in a stream of values. This implements a single-
  • HeapSelect
    This class tracks the smallest values seen thus far in a stream of values. This implements a single-
  • IntHeapSelect
    This class tracks the smallest values seen thus far in a stream of values. This implements a single-
  • PriorityQueue
    Priority Queue for index items.
  • FloatHeapSelect,
  • IQAgent,
  • SortUtils
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now