Question: LAB 4 - LINKED LIST (PART 1) Can anyone please help me solve Part 1, I am very confused and I don't know what to

LAB 4 - LINKED LIST (PART 1)

LAB 4 - LINKED LIST (PART 1) Can anyone please help me

solve Part 1, I am very confused and I don't know what

Can anyone please help me solve Part 1, I am very confused and I don't know what to do.

111= Linkedi.ist ([0,1,2,3,4]) print (111) \# note the order 4s preserued betow LinkedList: Head:Node(0)Tad1:Node(4)0>1>2>3>4None You will also need to add parameters for tracking the head (_head), tail (_tail), and length (_1en). You should name the parameters as given here, so the provided methods len, iter, and repr will work, Part 2 - Adding and removing Next, implement add_first(item), add_last (item), and remove_first (). All 3 methods should run in O(1). Part 3 - Exceptions remove_ irst () should raise a RuntimeError if called on an empty Linkedlist. Submitting At a minimum, subrit the following files: - Laba.py Stadents mut submit individually by the due date (typically, Sunday at 11:59 pm EST) to receive eredit. Module 4 Lab: Linked List Write a linked list that supports O(1) add first, add last, and remove first operations. Your starter code includes Lab4, py which has a complete Node class and a few methods in a Linkedtist class (1ter, len, and repr). It also includes TestLab4.py which has the full suite of test cases being run in Gradescope - feel free to run that locally to monitor your progreas and to consult it to help clarify expected behavior for methods. Part 1 - Constructor method with optional starting items In python, default arguments for functions are only initialized once. This means we should not nse a mutable argument as a default, since it can change over time: ... def _init _(self, L=[]):# Empty list is a BAD default self. L =L x=F000#x,L is the default eapty list y=Fo()#yL is the SAME defatrlt list X.L., append(3) [3] \$\$ y.L [3] If we want to make a custom collection with an optional collection of arguments, we should use an immutable like None for our default list, and create an empty list on the fly inside of our constructor method init: ... def _init _(self, L-None): if L is None: self.L - \#inew empty isst created for eury object: e2se: Gelf.L - L. 4 whatever the wser passed in x=Bar() >=Bar() x,L [3] y,L Cotuplete the constructor method for your Linkedilist class such that it takes an optional panumeter itema. Use Kone as the defuult value. If the value of Itams is Mone, then create in cmpty Linkedlist, Otherwise, the nser has passed in some colloction of items, and you nhould add than to your Linkelleist one at a time wing elthrr add_first of add_last. Choose the method that lets you muintain order when poesible

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!