Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1 (90 pts): In node_class.py, implement a class Node as follows: - (20 pts) The initializer should accept one argument: the data to be
Problem 1 (90 pts): In node_class.py, implement a class Node as follows: - (20 pts) The initializer should accept one argument: the data to be stored. Store the data in an instance variable data and the reference to the next node in an instance variable next. next should be initialized as None. Remark: - When we say "one argument", we mean one argument apart from self, similarly for future homework problems and exams. - None in Python is kind of like the "null" of C ++ and Java. You can search it online for more details. - (20 pts) Write a magic method to compare whether two instance objects of Nodes are equal: they are equal if and only if their instance variables data are equal. We assume that == already works on the data stored in data. For example: print(Node(10)==Node(10)) should print True. print(Node([10])==Node([10])) should print True. print(Node([11])==Node([10])) should print False. - (30 pts) Write magic methods such that the built-in str and repr functions can be used to return a string representation of the node. For example: n=Node(10)print(str(n))shouldprint10.n=Node(10)print(repr(n))shouldprintNode(10). print(eval(repr(n))==n) should print True, for n as an instance object of Node. We assume that str and repr already work on the data stored in the instance variable data. - (20 pts) write a method set_next which accepts one argument and sets next to it. You can assume that this argument is another instance object of Node. For example: n=Node(10) m=Node(20) n. set_next (m) print(n.next) should print 20
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