FAQ: Queues: Python - Queues Python Enqueue


#1

This community-built FAQ covers the “Queues Python Enqueue” exercise from the lesson “Queues: Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

Linear Data Structures

FAQs on the exercise Queues Python Enqueue

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hello people!

Can someone help me understand the Enqueue method? I think i understand well until de Else statement under the first If. Here:

  else:
    self.tail.set_next_node(item_to_add)
    self.tail = item_to_add
  self.size += 1

I just can’t understand why set the next node of the current tail to the item_to_add. When i think of a queue i think in setting the next node of item_to_add to the current tail, not the otherwise.

Thanks!


#3

You’re basically saying. If the Queue is NOT empty. Add John(item_to_add) to the back of the queue and tell Mary(tail), that was previously at the back, that John is now behind her. After that you tell your program, that Adam is now the “tail” of the queue.

Remember that “self.tail.set_next_node(item_to_add)” is telling the current tail, that item_to_add is coming after it.