Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please hellp...using PYTHON 3 Problem 1 Write a LinkedList class and a _Node class (note the leading underscore), representing a singly-linked, non-circular list. _Node should
Please hellp...using PYTHON 3
Problem 1 Write a LinkedList class and a _Node class (note the leading underscore), representing a singly-linked, non-circular list. _Node should exactly 3 methods: init__(val), get_next (), and get_val (). Note that this class does not allow users to change the value in a-Node, once set in-init-(val), this value is immutable. LinkedList should have the following methods:-init-() (creates an empty list), get_count) Note that since_Node is a private class, the functions take and returrn values instead of node objects. This means that add_head (val) must construct a -Node object. The "remove" and "peek" methods both return the value stored in the head of the list; the difference is that "remove" removes the node while returning, while "peek" keeps it on the list. Both the 'remove" and "peek" must raise errors if the list is empty; discus on the list. Both the "remove" and "peek" must raise errors if the list is empty; discuss with your group if an assert or an exception is more appropriate, and write down your decision below. (Don't forget to actually include the check in the code, too!) Include a tail pointer in your LinkedList class. Update it in add_head (val); also change it to None, in remove_head), if you remove the last element from the listStep 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