congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
SortUtils.swap
Code IndexAdd Tabnine to your IDE (free)

How to use
swap
method
in
smile.sort.SortUtils

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

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] < a[k] or
 * until we reach the top of the heap.
 */
public static void siftUp(double[] 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

/**
 * 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

/**
 * 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

/**
 * 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

/**
 * 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(int[] 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

/**
 * Reverses the order of the elements in the specified array.
 * @param a an array to reverse.
 */
public static void reverse(int[] 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

/**
 * Reverses the order of the elements in the specified array.
 * @param a an array to reverse.
 */
public static void reverse(float[] 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

/**
 * 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.
 */
public static void siftDown(float[] arr, int k, int n) {
  while (2*k <= n) {
    int j = 2 * k;
    if (j < n && arr[j] < arr[j + 1]) {
      j++;
    }
    if (arr[k] >= arr[j]) {
      break;
    }
    swap(arr, k, j);
    k = j;
  }
}
origin: com.github.haifengl/smile-math

/**
 * 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.
 */
public static void siftDown(double[] arr, int k, int n) {
  while (2*k <= n) {
    int j = 2 * k;
    if (j < n && arr[j] < arr[j + 1]) {
      j++;
    }
    if (arr[k] >= arr[j]) {
      break;
    }
    swap(arr, k, j);
    k = j;
  }
}
origin: com.github.haifengl/smile-math

/**
 * 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.
 */
public static void siftDown(int[] arr, int k, int n) {
  while (2*k <= n) {
    int j = 2 * k;
    if (j < n && arr[j] < arr[j + 1]) {
      j++;
    }
    if (arr[k] >= arr[j]) {
      break;
    }
    swap(arr, k, j);
    k = j;
  }
}
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 <T extends Comparable<? super T>> void siftUp(T[] arr, int k) {
  while (k > 1 && arr[k/2].compareTo(arr[k]) < 0) {
    swap(arr, k, k/2);
    k = k/2;
  }
}
origin: com.github.haifengl/smile-math

if (ir <= l + 1) {
  if (ir == l + 1 && arr[ir] < arr[l]) {
    SortUtils.swap(arr, l, ir);
  SortUtils.swap(arr, mid, l + 1);
  if (arr[l] > arr[ir]) {
    SortUtils.swap(arr, l, ir);
    SortUtils.swap(arr, l + 1, ir);
    SortUtils.swap(arr, l, l + 1);
      break;
    SortUtils.swap(arr, i, j);
origin: com.github.haifengl/smile-math

if (ir <= l + 1) {
  if (ir == l + 1 && arr[ir] < arr[l]) {
    SortUtils.swap(arr, l, ir);
  SortUtils.swap(arr, mid, l + 1);
  if (arr[l] > arr[ir]) {
    SortUtils.swap(arr, l, ir);
    SortUtils.swap(arr, l + 1, ir);
    SortUtils.swap(arr, l, l + 1);
      break;
    SortUtils.swap(arr, i, j);
origin: com.github.haifengl/smile-math

if (ir <= l + 1) {
  if (ir == l + 1 && arr[ir] < arr[l]) {
    SortUtils.swap(arr, l, ir);
  SortUtils.swap(arr, mid, l + 1);
  if (arr[l] > arr[ir]) {
    SortUtils.swap(arr, l, ir);
    SortUtils.swap(arr, l + 1, ir);
    SortUtils.swap(arr, l, l + 1);
      break;
    SortUtils.swap(arr, i, j);
origin: com.github.haifengl/smile-math

  /**
   * 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.
   */
  public static <T extends Comparable<? super T>> void siftDown(T[] arr, int k, int n) {
    while (2*k <= n) {
      int j = 2 * k;
      if (j < n && arr[j].compareTo(arr[j + 1]) < 0) {
        j++;
      }
      if (arr[k].compareTo(arr[j]) >= 0) {
        break;
      }
      SortUtils.swap(arr, k, j);
      k = j;
    }
  }
}
origin: com.github.haifengl/smile-math

if (ir <= l + 1) {
  if (ir == l + 1 && arr[ir].compareTo(arr[l]) < 0) {
    SortUtils.swap(arr, l, ir);
  SortUtils.swap(arr, mid, l + 1);
  if (arr[l].compareTo(arr[ir]) > 0) {
    SortUtils.swap(arr, l, ir);
    SortUtils.swap(arr, l + 1, ir);
    SortUtils.swap(arr, l, l + 1);
      break;
    SortUtils.swap(arr, i, j);
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

/**
 * 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

  /**
   * Sorts the specified array into ascending order.
   */
  public static <T extends Comparable<? super T>> void sort(T[] 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

/**
 * Sorts the specified array into ascending numerical order.
 */
public static void sort(double[] 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);
  }
}
smile.sortSortUtilsswap

Javadoc

Swap two positions.

Popular methods of SortUtils

  • siftDown
    To restore the max-heap condition when a node's priority is decreased. We move down the heap, exchan

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • getSupportFragmentManager (FragmentActivity)
  • getSystemService (Context)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Join (org.hibernate.mapping)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now