Q. When should I call the
A. Just as with any other class, you should call the
_Node constructor when you want to create a new
_Node object (a new node in the linked list). You should not use it to create a new reference to an existing
_Node object. For example, the code
oldfirst = _Node(item, next)oldfirst = first
creates a new _
Node object, then immediately loses track of the only reference to it. This code does not result in an error, but it is a bit untidy to create orphans for no reason.
Q. Why not define
Node as a stand-alone class in a separate file named
A. By defining
_Node in the same file as
linkedqueue.py and giving it a name that begins with an underscore, we encourage clients of ...