Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 3 class LinkNode: def _init__(self, value,nxt-None) assert isinstance (nxt,LinkNode) or nxt is None self.next nxt self.head None def get_value(self): def set value (self,value): def
Python 3
class LinkNode: def _init__(self, value,nxt-None) assert isinstance (nxt,LinkNode) or nxt is None self.next nxt self.head None def get_value(self): def set value (self,value): def get_next(self) def set_next(self,nxt): def _repr__(self) return self.value self.va lue va Lue return self.next self.next = nxt return repr(self.value)+ ", " + repr(self.next) Question 2.6. Insert at the given location Implement insertat which takes a linked-list, an element elem and an insertion index pos and returns the first element of the list with the element inserted at the correct location. def insert_at (elem, pos, link): >>> temp = None >>>insert_at (LinkNode (6),0, temp) 6, None >>> temp = Link ode (5) >>> insert_at (LinkNode (6),0, temp) 6, 5, None >>> temp = LinkNode (5) >insert_at (LinkNode (6),1, temp) 5, 6, None >>> temp = LinkNode ( 5 , Link Ode ( 6 , LinkNode ( 7 ) ) ) >>>insert_at (LinkNode (8),2, temp) 5, 6, 8, 7, None Question 2.7: Remove at a location Implement remove_at which takes a linked-list and a removal index pos and returns the first element of the list with the element removed from the correct location. def remove_at(pos, link): 1nn >>> temp = LinkNode ( 5 , LinkNode ( 6 , Link Ode ( 7 ) ) ) >>remove at (0,temp 6, 7, None >>> temp = LinkNode ( 5 , LinkNode ( 6 , LinkNode ( 7 ) ) ) >>> remove_at (2,temp) 5, 6, None >>> temp = LinkNode ( 5 , LinkMode ( 6 , LinkNode ( 7 ) ) ) >>> remove_at(1,temp) 5, 7, NoneStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started