Singly Linked List
Start Timer
0:00:00
Singly-linked lists are a type of linked list where nodes have only one pointer: A pointer to the next element. Create a class SinglyLinkedList along with its methods:
add_head(element)- adds an element to the head of the list. This becomes the new head of the linked list.add_tail(element)- adds an element to the tail of the list. This becomes the new tail of the linked list.remove_head() -> element- removes the head and returns the value of the removed element.remove_tail() -> element- removes the tail and returns the value of the removed element.__contains__(item) -> bool- checks if the item is inside the list. ReturnsTrueif it is inside the list and returnsFalseif not. This method is implemented to allow the use of Python’sinoperator.__getitem__(index)- returns the element at the specified index. Raises anIndexErrorif the index is out of bounds. This method is implemented to allow the use of Python’s[]operator.__len__()- returns the length of theSinglyLinkedList.
.
.
.
.
.
.
.
.
.
Comments