0

When I implemet the dequeue() method, and in the following code

    def dequeue(self): 
        if self.is_empty(): 
            print("The Queue is empty")
            return
        answer = self._head._element 
#---------------------
        self._head = self._head._next #here, what happens with the "lost" node, because i think it is lost by the linked list
#---------------------
        self._size -= 1
        if self.is_empty():
            self._tail = None
        return answer

Is that node retrieved by the garbage collector?, because when i lost the reference to that node, and i have no way to access it. The node is implemented as following within a LinkedList class.

class _Node:
   __slots__ = "_element","_next"
   def __init__(self, element, next): 
       self._element = element 
       self._next = next

1 Answer 1

0

Yep, it's a notation, and the garbage collector knows when to retrieve unused data.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.