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!