Direct Insert Sort

Source: Internet
Author: User

Direct Insert Sort:

Algorithm steps:

1) Think of the first ordered column as the first ordinal sequence, the second element to the last element as an unordered sequence.

2) scan the unsorted sequence once from the head, inserting each element scanned into the appropriate position of the ordered sequence. (If the element you want to insert is equal to an element in an ordered sequence, insert the element you want to insert behind the equal element)

Algorithm:


Algorithm implementation:
public class Insertsort {    void sort (int[] array) {        for (int i = 1; i < Array.Length; i++) {           //The data            being marked for comparison int currentvalue = Array[i];            Int J;            If the data in front of the data being labeled for comparison is larger than the tag data, move the data that is larger than the tagged data back one for            (j = i-1; j > 0; j--) {                if (CurrentValue < array[j]) {
   array[j + 1] = Array[j];                } else {break                    ;                }            }            ARRAY[J+1] = CurrentValue;        }    }



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Insert sort directly

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.