Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

repr ( node 1 ) instead of node 1 . _ - ( ) x + y instead of x * . _ add _

repr(node1) instead of node1._-()
x+y instead of x*._ add_-(y)
object1== object2 instead of object1.(object2)
len(collection) instead of collection.
This applies to test cases and functionality within a class. The magic syntax is preferred because it improves
readability. The only common exception is when calling super()._-.
Part 2- class LinkedList
In the same files as above, but in different classes (LinkedList and TestLinkedList), implement the
LinkedList class as described below.
LinkedList
head: Node | None
_tail: Node | None
len: int
init (self, items: Optional[Iterable[Any]])-> None
Len (self)-> int
get_head(self)-> Any | None
get_tail(self)-> Any | None
add_last(self, item: Any)-> None
add_first(self, item: Any)-> None
remove_last(self)-> Any
remove_first(self)-> Any
Figure 2: Class diagram for LinkedList. Note that items in LinkedList. is an optional paramter
(it defaults to None, and it can be any iterable if included. This means lists, tuples, sets, dictionaries, strings,
or even the range object are fair game.)
init(self, items: Optional [Iterable[Any])-> None
optional collection items are sequentially added to LinkedList if included
use add_last () to add items in correct order
get_head(self) Any I None
Returns item stored in self ._head, or None for an empty LinkedList
get_tail(self) Any I None
Returns item stored in self ._tail, or None for an empty LinkedList
add_first(self, item: Any)-> None
adds a node to the front of the LinkedList with item
add_last(self, item: Any)-> None
adds a node to the end of the LinkedList with item
remove_first(self)-> Any
removes first node from LinkedList and returns its item
raises a RuntimeError if LinkedList is empty when called
remove_last(self)--> Any
removes last node from LinkedList and returns its item
raises a RuntimeError if LinkedList is empty when called
Flow:
Empty initialization
Red: test_linkedlist.py, TestLinkedList class:
Create empty LinkedList e.g. LL1= LinkedList()
Assert length is correct (should be 0)
Assert get_head() and get_tail() return correct values (should be None)
Green:
linkedlist.py, LinkedList class:
Implement _-_,-, get_head(), and get_tail()
add_last
Red: test_linkedlist.py, TestLinkedList class:
Create an empty LinkedList
Using a for loop, sequentially add items to end of LinkedList. With each add, assert that
you get the correct values from:
** len ()
get_head()
get_tail()
, Green:
linkedlist.py, LinkedList class:
Implement add_last
Non-empty initialization
Red: test_linkedlist.py, TestLinkedList class:
initialize a new linked list with some iterable, e.g.:
LL1= LinkedList (['a','b','c'])
LL1= LinkedList (range (10))
Test you get correct values from len, get_head(), and get_tail()
Green:
linkedlist.py, LinkedList class:
Finish implementing _
See note on default parameters below
add_first
Test similar to add_last
Implement
remove_first
Red: test_linkedlist.py, TestLinkedList class:
Build up a linked list (either create a non-empty list, or use add_first or add_last)
Iteratively call remove_first() until the LinkedList is empty. With every remove_first()
call, assert you get correct values from:
remove_first ()(should return item in first node)
image text in transcribed

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

More Books

Students also viewed these Databases questions