Unlike an unordered list, an ordered list stores ordered elements, such as ascending or descending. In the implementation of many ordered lists, you certainly cannot find operations similar to addAfter, because it is one of the features of unordered lists. Unlike an unordered list, an ordered list stores ordered elements, such as ascending or descending. In the implementation of many ordered lists, you certainly cannot find operations similar to addAfter, because it is one of the features of unordered lists.
Generally, the ordered list provides several basic operations:
1. add is used to add elements to the list and maintain its orderly state.
2. get operation, used to obtain the elements under the specified index
3. Get the length of the list by using the length attribute or method.
In these operations, add is the most important part, which is usually composed of three parts (taking incremental sequence as an example ):
1. traverse the list from left to right until an element greater than or equal to the inserted value is found. The position of the element is the position to be inserted.
2. Move the element on the right of the insert position one by one
3. Insert the value to this position
Function SortedList () {this. length = 0; this. elementData = [];} SortedList. prototype. add = function (val) {var array = this. elementData; for (var I = 0; I = I; j --) {array [j + 1] = array [j];} array [I] = val; this. length ++;} SortedList. prototype. get = function (I) {return this. elementData [I];}
The above is the JavaScript interesting question: the content of the ordered list. For more information, see the PHP Chinese website (www.php1.cn )!