Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions