Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

=+2. Who is the audience?

Answered: 1 week ago