class LinkedList:
"""Linked list class"""
def __init__(self: 'LinkedList', item: object=None,
rest: 'LinkedList'=None) -> None:
"""Create a new LinkedList
item - The first element of the linked list,
Not present if self will be the empty linked list.
rest - The linked list that contains the elements after item.
Not present if self will be the empty linked list."""
self.empty = (item is None) and (rest is None)
if not self.empty:
self.item = item
if rest is None:
self.rest = LinkedList()
else:
self.rest = rest
This week's lab is more easier for my partner and I to finish, because we have read and learnt more materials of LinkedList. To learn this stuff well, we should always think carefully about the recursion method. A few weeks are left, I think I should practise more to think up the code much more quickly and correctly.
No comments:
Post a Comment