MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / append

Method append

data_structures/linked_list/print_reverse.py:54–69  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 9

extendMethod · 0.95
is_palindrome_stackFunction · 0.45
is_palindrome_dictFunction · 0.45
__str__Method · 0.45
__str__Method · 0.45
__str__Method · 0.45
_locate_nodeMethod · 0.45
insertMethod · 0.45
__iter__Method · 0.45

Calls 1

NodeClass · 0.70

Tested by

no test coverage detected