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 elements of the list.

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

  3. Add a method to the classic LinkedList class that returns the last element 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. ...

Get A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition 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.