Question: PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem Given the LinkedList implementation we saw in class, complete the method insert() to insert a new element

PYTHON 3

PLEASE FOLLOW INSTRUCTIONS

COMPLETE CODE

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem Given the LinkedList implementation

Problem

Given the LinkedList implementation we saw in class, complete the method insert() to insert a new element with the given value at the i-th position. If i is greater than the length of the list, just insert the new element at the end.

CODE:

class Node: def __init__(self, value): self.value = value self.next = None

class LinkedList: def __init__(self): self.first = None def insert(self, i, value): # TODO def printItems(self): current = self.first while current is not None: print(current.value, end=" ") current = current.next my_list = LinkedList() my_list.insert(0, "b") my_list.insert(0, "a") my_list.insert(2, "d") my_list.insert(2, "c") my_list.insert(5, "e") my_list.printItems() # should print a b c d e

nstructions trom your feacher 1 class Node: 2 def init..(self, value): Problem self.value value self.next None Given the LinkedList implementation we saw in class, complete the method insert) to insert a new element with the given value at the i-th position. If i is greater than the length of the list, just insert the new element at the end. 6 class LinkedList: 7 def _init_(self): self. first = None 9 10 def insert(self, i, value): #T000 12 13 def printItems(self): 14 15 16 current self.first while current is not None: print(current.value, end-" current current.next 19 my list - LinkedListO 20 my_list.insert(0, "b" 21 my list.insert(0, "a") 22 my_list.insert(2, "d") 23 my_list.insert(2, "c" 24 my_list.insert(5, "e" 25 my.list.printitems() # should print a b c d e

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!