
Data Structures and Algorithms Interview
0 of 20 Completed
Introduction to Linked Lists
Linked List Operations
Assessment 1: Singly Linked Lists
Assessment 2: Pop Tail!
Linked Lists VS. Arrays
Assessment 3: Cyclic Detection
Assessment 4: Swapping Nodes
Assessment 1: Singly Linked Lists
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. ReturnsTrue
if it is inside the list and returnsFalse
if not. This method is implemented to allow the use of Python’sin
operator.__getitem__(index)
- returns the element at the specified index. Raises anIndexError
if the index is out of bounds. This method is implemented to allow the use of Python’s[]
operator.__len__()
- returns the length of theSinglyLinkedList
.
0%
CompletedYou have 20 sections remaining on this learning path.
Advance your learning journey! Go Premium and unlock 40+ hours of specialized content.