Exercises

The following exercises provide you with the opportunity to practice with linked lists. The solutions to these exercises are found in the section Chapter 14.

  1. Add a method to the classic LinkedList class that prints all the values of the list.

  2. Add a method to the DoublyLinkedList class that prints all the values of the list in reverse order.

  3. Add a method to the classic LinkedList class that returns the last value from the list. Assume you don’t know how many elements are in the list.

  4. Here’s a tricky one. Add a method to the classic LinkedList class that reverses the list; that is, if the original list is A -> B -> C, all of the list’s links should change so that C -> B -> A.

  5. Here’s a brilliant little linked list puzzle for you. Let’s ...

Get A Common-Sense Guide to Data Structures and Algorithms in Python, Volume 1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.