CSCA48H3 Lecture Notes - Lecture 3: Linked List, Newline, Repeating Decimal
Document Summary
We have seen examples of attributes that refer to other objects, which we called embedded references. A common data structure, the linked list, takes advantage of this feature. Linked lists are made up of nodes, where each node contains a reference to the next node in the list. In addition, each node contains a unit of data called the cargo. 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. Recursive data structures lend themselves to recursive methods: the node class. As usual when writing a new class, we"ll start with the initialization and __str__ methods so that we can test the basic mechanism of creating and displaying the new type: As usual, the parameters for the initialization method are optional.