Question
i need to create methods that: append_element(self, val) This method should increase the size of the list by one, adding the specified value in the
i need to create methods that:
append_element(self, val) This method should increase the size of the list by one, adding the specified value in the new tail position. This is the only way to add a value as the tail.
insert_element_at(self, val, index) If the provided index identifies a valid zero-based position within the list, then insert the specified value at that position, increasing the length by one. This method can be used to insert at the head of a non-empty list, but cannot append to a list. The provided index must be within the current bounds of the list. If the index is not valid, raise an IndexError exception.
remove_element_at(self, index) If the provided index identifies a valid zero-based position within the list, then remove and return the value stored in a Node at that position. If the index is not valid, raise an IndexError exception.
get_element_at(self, index) If the provided index identifies a valid zero-based position within the list, then obtain the value from the Node at that position and return it. Do not unlink the Node object. If the index is not valid, raise an IndexError exception.
class Linked_List:
class __Node:
def __init__(self, val):
# declare and initialize the private attributes
# for objects of the Node class.
# TODO replace pass with your implementation
pass
def __init__(self):
# declare and initialize the private attributes
# for objects of the sentineled Linked_List class
# TODO replace pass with your implementation
pass
def __len__(self):
# return the number of value-containing nodes in
# this list.
# TODO replace pass with your implementation
pass
def append_element(self, val):
# increase the size of the list by one, and add a
# node containing val at the new tail position. this
# is the only way to add items at the tail position.
# TODO replace pass with your implementation
pass
this is python
Step 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