data_structures.linked_list.print_reverse¶
Attributes¶
Classes¶
A class to represent a Linked List. |
|
Functions¶
|
Prints the elements of the given Linked List in reverse order |
|
Creates a Linked List from the elements of the given sequence |
Module Contents¶
- class data_structures.linked_list.print_reverse.LinkedList¶
A class to represent a Linked List. Use a tail pointer to speed up the append() operation.
- __iter__() collections.abc.Iterator[int] ¶
Iterate the LinkedList yielding each Node’s data. >>> linked_list = LinkedList() >>> items = (1, 2, 3, 4, 5) >>> linked_list.extend(items) >>> tuple(linked_list) == items True
- __repr__() str ¶
Returns a string representation of the LinkedList. >>> linked_list = LinkedList() >>> str(linked_list) ‘’ >>> linked_list.append(1) >>> str(linked_list) ‘1’ >>> linked_list.extend([2, 3, 4, 5]) >>> str(linked_list) ‘1 -> 2 -> 3 -> 4 -> 5’
- append(data: int) None ¶
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 -> 2’
- extend(items: collections.abc.Iterable[int]) None ¶
Appends each item to the end of the LinkedList. >>> linked_list = LinkedList() >>> linked_list.extend([]) >>> str(linked_list) ‘’ >>> linked_list.extend([1, 2]) >>> str(linked_list) ‘1 -> 2’ >>> linked_list.extend([3,4]) >>> str(linked_list) ‘1 -> 2 -> 3 -> 4’
- data_structures.linked_list.print_reverse.in_reverse(linked_list: LinkedList) str ¶
Prints the elements of the given Linked List in reverse order >>> in_reverse(LinkedList()) ‘’ >>> in_reverse(make_linked_list([69, 88, 73])) ‘73 <- 88 <- 69’
- data_structures.linked_list.print_reverse.make_linked_list(elements_list: collections.abc.Iterable[int]) LinkedList ¶
Creates a Linked List from the elements of the given sequence (list/tuple) and returns the head of the Linked List. >>> make_linked_list([]) Traceback (most recent call last):
…
Exception: The Elements List is empty >>> make_linked_list([7]) 7 >>> make_linked_list([‘abc’]) abc >>> make_linked_list([7, 25]) 7 -> 25
- data_structures.linked_list.print_reverse.linked_list¶