Javascript: double-stranded table-insert sorting

Source: Internet
Author: User

Insert sorting in the case of Array StorageAlgorithmIn the worst case, the previous elements need to be constantly moved to the backend so as to leave a blank space at the insertion point so that the target element can be inserted.

When you replace it with a linked list, you obviously do not need to do this kind of movement. Based on the "Pointer" of each node's precursor node, locate the insertion point and directly remove the target value from the original linked list, then, break the Linked List into two parts at the insertion point, and then re-connect it with the target point.

<! Doctype HTML> 

-- Before sorting ---

10 9 8 7 6 5 4 3 2 1

9 10 8 7 6 5 4 3 2 1

8 9 10
7 6 5 4 3 2 1

7 8 9 10 6 5 4 3 2 1

6 7 8 9 10 5 4 3 2 1

5 6 7 8 9 10 4 3 2 1

4 5 6 7 8 9 10 3 2 1

3 4 5 6 7 8 9 10 2 1

2 3 4 5 6 7 8 9 10 1

1 2 3 4 5 6 7 8 9 10

-- After sorting ---

1 2 3 4 5 6 7 8 9 10

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.