Question
Implement a simple linked list in Python (Write source code and show output) with basic linked list operations like: (a) create a sequence of nodes
Implement a simple linked list in Python (Write source code and show output) with basic linked list operations like:
(a) create a sequence of nodes and construct a linear linked list.
(b) insert a new node in the linked list.
(b) delete a particular node in the linked list.
(c) modify the linear linked list into a circular linked list.
Use this:
class Node: def __init__(self, val=None): self.val = val self.next = None class LinkedList: """ TODO: Remove the "pass" statements and implement each method Add any methods if necessary DON'T use a builtin list to keep all your nodes. """ def __init__(self): self.head = None # The head of your list, don't change its name. It should be "None" when the list is empty. def append(self, num): # append num to the tail of the list pass def insert(self, index, num): # insert num into the given index pass def delete(self, index): # remove the node at the given index and return the deleted value as an integer pass def circularize(self): # Make your list circular. pass if __name__ == "__main__": my_list = LinkedList() # [] my_list.insert(0, 32) # [32] my_list.append(-5) # [32, -5] my_list.append(19) # [32, -5, 19] my_list.insert(1, 6) # [32, 6, -5, 19] my_list.delete(2) # [32, 6, 19] my_list.circularize()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started