Python Queue Implementation Exercise

Queues | Codecademy

For this exercise, I am confused as to why, in the enqueue method, when adding to the queue, we use self.tail.set_next_node(item_to_add) as opposed to self.tail.set_prev_node(item_to_add).

This is because when we add to a queue, are we not added to the back of the queue? So, we should have the new node to be added behind the tail?

Thanks for any help.


1 Like

If you start at the head, then the second one in the queue is the β€˜next’ one. So, next is going down the queue to the tail and prev is going back towards the head.

1 (head) β†’ 2 β†’ 3 β†’ 4(tail)

Hope that helps.