We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Remove from Head

We're one method away from having a fully functioning O(1) Queue! We just need a way to remove the first element from the linked list in constant time. When we're finished, our LinkedList will fulfill the basic requirements of a Queue:

  • add_to_tail: Constant time insert
  • remove_from_head: Constant time pop

Let's rename the LinkedList class to LLQueue and remove the add_to_head functionality because Queues don't allow inserting into the wrong end.

We've also flipped the arrows in the printed representation to reflect the change.

Assignment

Complete the remove_from_head method. It should remove the first node from the list (the head) and return it.