Examples of double-stranded table insertion sorting based on javascript data structure, and javascript Data Structure
This article describes how to sort two-chain table insertion based on javascript data structure. We will share this with you for your reference. The details are as follows:
Under the premise of Array Storage, insert the sorting algorithm. In the worst case, the previous elements need to be constantly moved to the back, 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>
The running result is as follows:
-- 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 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
I hope this article will help you design JavaScript programs.