It is possible to implement a queue using a linked list such that both enqueue and dequeue have \(O(1)\) performance on average. In this case it means that most of the time enqueue and dequeue will be \(O(1)\) except in one particular circumstance where dequeue will be \(O(n)\text{.}\)
To implement the length method, we counted the number of nodes in the list. An alternative strategy would be to store the number of nodes in the list as an additional piece of data in the head of the list. Modify the UnorderedList class to include this information and rewrite the length method.
Implement a slice method for the UnorderedList class. It should take two parameters, start and stop, and return a copy of the list starting at the start position and going up to but not including the stop position.
Consider the relationship between Unordered and Ordered lists. Is it possible that inheritance could be used to build a more efficient implementation? Implement this inheritance hierarchy.
The linked list implementation given above is called a singly linked list because each node has a single pointer to the next node in sequence. An alternative implementation is known as a doubly linked list. In this implementation, each node has a pointer to the next node (commonly called next) as well as a pointer to the preceding node (commonly called back). The head pointer also contains two pointers, one to the first node in the linked list and one to the last. Code this implementation in C++.