This week we learnt Linked lists.Linked lists are made up of nodes, where each node contains a reference to the next node in the list. A linked list is considered a recursive data structure because it has a recursive definition.
A linked list is either: the empty list, represented by None, or a node that contains a cargo object and a reference to a linked list.
Here are some examples:
class LListNode:
"""Node to be used in linked list"""
def __init__(self: 'LListNode', value: object =None,
nxt: 'LListNode' =None) -> None:
"""Create a new LListNode"""
self.value, self.nxt = value, nxt
def __repr__(self: 'LListNode') -> str:
"""String representation of this LListNode"""
return 'LListNode(' + str(self.value) + ', ' + str(self.nxt) + ')'
No comments:
Post a Comment