Question: class SLNode: Singly Linked List Node class DO NOT CHANGE THIS CLASS IN ANY WAY def _ _ init
class SLNode:
Singly Linked List Node class
DO NOT CHANGE THIS CLASS IN ANY WAY
def initself value: object, nextNone None:
self.value value
self.next next
from SLNode import
class SLLExceptionException:
Custom exception class to be used by Singly Linked List
DO NOT CHANGE THIS CLASS IN ANY WAY
pass
class LinkedList:
def initself startlistNone None:
Initialize new linked list
DO NOT CHANGE THIS METHOD IN ANY WAY
self.head SLNodeNone
# populate SLL with initial values if provided
# before using this feature, implement insertback method
if startlist is not None:
for value in startlist:
self.insertbackvalue
def strself str:
Return content of singly linked list in humanreadable form
DO NOT CHANGE THIS METHOD IN ANY WAY
out SLL
node self.head.next
while node:
out strnodevalue
if node.next:
out
node node.next
out
return out
def lengthself int:
Return the length of the linked list
DO NOT CHANGE THIS METHOD IN ANY WAY
length
node self.head.next
while node:
length
node node.next
return length
def isemptyself bool:
Return True is list is empty, False otherwise
DO NOT CHANGE THIS METHOD IN ANY WAY
return not self.head.next
# #
def insertfrontself value: object None:
TODO: Write this implementation
pass
def insertbackself value: object None:
TODO: Write this implementation
pass
def insertatindexself index: int, value: object None:
TODO: Write this implementation
pass
def removeatindexself index: int None:
TODO: Write this implementation
pass
def removeself value: object bool:
TODO: Write this implementation
pass
def countself value: object int:
TODO: Write this implementation
pass
def findself value: object bool:
TODO: Write this implementation
pass
def sliceself startindex: int, size: int "LinkedList":
TODO: Write this implementation
pass
if namemain:
print
# insertfront example
testcase ABC
lst LinkedList
for case in testcase:
lstinsertfrontcase
printlst
print
# insertback example
testcase CBA
lst LinkedList
for case in testcase:
lstinsertbackcase
printlst
print
# insertatindex example
lst LinkedList
testcases ABCDEF
for index, value in testcases:
printInserted value, at index", index, : end
try:
lstinsertatindexindex value
printlst
except Exception as e:
printtypee
print
# removeatindex example
lst LinkedList
printfInitial LinkedList : lst
for index in :
printRemoved at index", index, : end
try:
lstremoveatindexindex
printlst
except Exception as e:
printtypee
print
# remove example
lst LinkedList
printfInitial LinkedList, Length: lstlength
lst
for value in :
printfremovevalue: lstremovevalue Length: lstlength
f
lst
print
# remove example
lst LinkedList
printfInitial LinkedList, Length: lstlength
lst
for value in :
printfremovevalue: lstremovevalue Length: lstlength
f
lst
print
# count example
lst LinkedList
printlst lstcount lstcount lstcount lstcount
print
# find example
lst LinkedListWaldo "Clark Kent", "Homer", "Santa Claus"
printlst
printlstfindWaldo
printlstfindSuperman
printlstfindSanta Claus"
print
# slice example
lst LinkedList
llslice lstslice
printSource: lst
printStart: Size: : llslice
llslice.removeatindex
printRemoved at index : llslice
print
# slice example
lst LinkedList
printSource: lst
slices
for index, size in slices:
printStart: index, "Size:", size, end
try:
print : lstsliceindex size
except:
print : exception occurred."
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
