Doubly linked list
The transaction log of the previous section is due for an upgrade. The product team wants to enable users to be able to examine the log by going through itforwardandbackwardto see what each step does. This is bad news for the regular linked list, as it's really inefficient to go anywhere other than forward. So, how is this rectified?
It is rectified using the doubly linked list. The doubly linked list introduces the link back
. While this sounds like a minor change, it allows to work on that list backward as well as forward, which significantly improves the ability to look up items. By augmenting the previous singly linked list item with a back pointer, the doubly linked list is almost created:
#[derive(Debug, Clone)] structNode { value: String, next: Link, prev: Link, } typeLink = Option<Rc<RefCell<Node>>>; #[derive(Debug, Clone)] pubstructBetterTransactionLog { head: Link, tail: Link, pub length: u64, }
Similar to the singly linked list, the list...