Java Implementation Insert Sort

Source: Internet
Author: User

1.1. Algorithmic thinking

Direct insertion sorting is a simple interpolation method, and the basic idea is to insert the records to be sorted into an ordered sequential sequence by the size of their key values, until all the records have been inserted so that a new ordered sequence is obtained.

algorithm ideas for inserting sorting:

(1) Set the monitoring whistle r[0], assign the value of the record to be inserted to r[0];

(2) Set the position of the start search J;

(3) in the array to search, the search will be the first J record, until R[0].key≥r[j].key;

(4) Place r[0] into the r[j+1] position.

1.2. Java implementation

bubblesorttest

 

package ch03; public class Bubblesorttest {public static void main (string[] args) {int[] Srcarr = {2,5,7,1,9,34,22,             15};             int[] Bubblesort = Bubblesort (Srcarr);       for (int i:bubblesort) {System.out.println (i);  }}/** * method Description: Bubble Sorting algorithm * * @param srcarr * @return * */public static Int[] Bubblesort (int[] srcarr) {for (int i = 0, i < srcarr.length; i++) {for (int j = 0; J < SR                  Carr.length-i-1;j++) {if (srcarr[j]>srcarr[j+1]) {int temp = srcarr[j];                  SRCARR[J] = srcarr[j+1];              SRCARR[J+1] = temp;    }}} return Srcarr; }} 


 

Java Implementation Insert Sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.