JavaScript sorting algorithm

Source: Internet
Author: User

Common sorting methods Introduction to Algorithms Algorithm description Algorithm implementation Algorithm analysis
Insert algorithm By constructing an ordered sequence, for unsorted data, in the sorted sequence from backward to forward scan, find the appropriate location and insert. The insertion sort is implemented on an implementation, usually in the order of In-place (that is, the ordering of extra space that only needs O (1), so that in the backward-forward scanning process, the sorted elements need to be moved backwards and forwards to provide the insertion space for the newest elements.

1. Starting with the first element, the element can be considered to have been sorted;

2. Remove the next element and scan from the back forward in the sequence of elements that have been sorted;

3. If the element (sorted) is greater than the new element, move the element to the next position;

4. Repeat step 3 until the sorted element is found to be less than or equal to the position of the new element;

5. Insert the new element into the position;

6. Repeat step 2~5;

JavaScript sorting algorithm

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.