SortedListedList
Last updated
Was this helpful?
Last updated
Was this helpful?
A sorted linked list is a list that keeps its elements sorted. To keep all elements sorted, instead of applying a sorting algorithm. - Learning JavaScript Data Structures and Algorithms Third Edition
All methods will same as the . we will only overwrite the insert method.
.
The SortedLinkedList class does not need and additional properties, so we can simply extend the LinkedList Class, only overwrite the required methods.
While Insert an element in SortedLinkedList, There are two scenarios:-
SortedLinkedList is Empty
SortedLinkedList is Not Empty
Get the Next Sorted Position/Index using the getNextSortIndex method.
This method returns the sorted index by iteratively comparing the element with the linked list's nodes or until all nodes have been iterated.
The complexity of the Sorted Linked List will be the same as Single Linked List.
Called Parent and set the index to zero.
Called Parent and set the index to Next Sorted Position.
you get the full source