Created
November 29, 2021 17:44
-
-
Save kelvingakuo/e9a8e7116d8346ffd35040135baa0da7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DoublyLinkedNode(object): | |
def __init__(self, value: BPlusTreeNode) -> None: | |
""""Init a doubly-linked list node | |
Params: | |
value (BPlusTreeNode) - The value of the node as a B+ tree node, specifically leaf node | |
""" | |
if(type(value) != BPlusTreeNode): | |
print("The value of the node needs to be a BPlusTreeNode") | |
else: | |
self.value = value | |
self.prev = None | |
self.next = None | |
def print_node(self) -> str: | |
prv = obj_id(self.prev.value) if self.prev is not None else None | |
nxt = obj_id(self.next.value) if self.next is not None else None | |
return f"([Prev node: {prv}] Value: {obj_id(self.value)}. [Next node: {nxt}])" | |
class DoublyLinkedList(object): | |
def __init__(self) -> None: | |
""" Init a doubly-linked list. Inits a head node as None | |
""" | |
self.head = None | |
if __name__ == "__main__": | |
a = DoublyLinkedNode(BPlusTreeNode(4) | |
b = DoublyLinkedNode(BPlusTreeNode(4) | |
c = DoublyLinkedNode(BPlusTreeNode(4) | |
d = DoublyLinkedNode(BPlusTreeNode(4) | |
e = DoublyLinkedNode(BPlusTreeNode(4) | |
a.prev = None | |
a.next = b | |
b.prev = a | |
b.next = c | |
c.prev = b | |
c.next = d | |
d.prev = c | |
d.next = e | |
e.prev = d | |
e.next = None | |
doubly_linked_list = DoublyLinkedList(a) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment