Example of Java simulating ordered linked list data structure
Ordered linked list: sort by key value. When the chain head is deleted, the minimum (/ maximum) value is deleted. When inserting, the insertion position is searched. When inserting, you need to compare o (n), the average o (n / 2), and the efficiency of deleting the smallest (/ largest) data at the chain head is O (1). If an application needs to frequently access (insert / find / delete) the smallest (/ largest) data items, then the ordered linked list is a good choice. Priority queue can use the ordered linked list to realize the insertion and sorting of the ordered linked list: for an unordered array, The ordered linked list is used to sort. The comparison time level is O (n ^ 2). The replication time level is O (2 * n). Because the number of copies is less, the data put into the linked list is moved n times for the first time, and then copied from the linked list to the array n times. Each time a new link node is inserted, there is no need to copy and move the data, but only need to change the chain field of one or two link nodes
Reverse order of single linked list: