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

高洛峰
Release: 2017-01-16 15:36:50
Original
1465 people have browsed it

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;
  }
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template