Appends a new node with the given data to the end of the LinkedList. >>> linked_list = LinkedList() >>> str(linked_list) '' >>> linked_list.append(1) >>> str(linked_list) '1' >>> linked_list.append(2) >>> str(linked_list) '1 ->
(self, data: int)
| 52 | return " -> ".join([str(data) for data in self]) |
| 53 | |
| 54 | def append(self, data: int) -> None: |
| 55 | """Appends a new node with the given data to the end of the LinkedList. |
| 56 | >>> linked_list = LinkedList() |
| 57 | >>> str(linked_list) |
| 58 | '' |
| 59 | >>> linked_list.append(1) |
| 60 | >>> str(linked_list) |
| 61 | '1' |
| 62 | >>> linked_list.append(2) |
| 63 | >>> str(linked_list) |
| 64 | '1 -> 2' |
| 65 | """ |
| 66 | if self.tail: |
| 67 | self.tail.next_node = self.tail = Node(data) |
| 68 | else: |
| 69 | self.head = self.tail = Node(data) |
| 70 | |
| 71 | def extend(self, items: Iterable[int]) -> None: |
| 72 | """Appends each item to the end of the LinkedList. |
no test coverage detected