Home >Java >javaTutorial >Java data structure and algorithm insertion algorithm to implement numerical sorting example

Java data structure and algorithm insertion algorithm to implement numerical sorting example

高洛峰
高洛峰Original
2017-01-16 15:36:501489browse

The example of this article describes the insertion algorithm of Java data structure and algorithm to achieve numerical sorting. Share it with everyone for your reference. The details are as follows:

Written here as a commemoration. The key is to understand the insertion point. At the insertion point, the initial in and out are both at this insertion point, and then the in is automatically decremented. Reorder the array

public static void insertSort(){
  for(int out=1; out<a.length; out++){
    int temp = a[out];
    int in = out;
    while(in>0&& a[in-1]>temp){
      a[in] = a[in-1];
      --in;
    }
    a[in] = temp;
  }
}

I hope this article will be helpful to everyone in java programming.

For more java data structures and algorithms, insertion algorithm implementation of numerical sorting examples and related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn