Introductory Laboratory on Linked Lists

Introduction to Singly-Linked Lists

Summary: This laboratory helps you gain more experience with the use of lists and pointers.

This lab involves working with lists of data, using an approach simplified somewhat from Section 6.3 of Bailey's text. In particular,

Steps for this Lab

  1. Review Bailey's discussion of SinglyLinkedListElement and SinglyLinkedList to be sure you understand that material.

  2. Copy SinglyLinkedListElement and OurSinglyLinkedList to your account and compile them.

  3. In OurSinglyLinkedList, review the new main to see how it may be used for testing. Then run this program with several test cases in order to gain experience with this main testing method.
    Such a menu-driven framework often provides a flexible approach for testing specific methods.

  4. Methods contains, remove, and toString all contain loops that allow processing to work through the list. Follow a similar approach to implement the details for method printLast, that should print the data for the last item on the list. (If the list is null, the method should print a message to that effect instead.)

    To perform this task, you have to move along the list item-by-item until coming to the end, where the next field is null.

  5. Write the details for method count (String item) which counts the number of times a designated item occurs on the list.

    To perform this task, you will want to move along the list item-by-item, counting the items as you go.

This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~walker/courses/152.sp01/lab-lists-intro.html

created March 12, 2001
last revised March 13, 2001
Henry Walker (walker@cs.grinnell.edu)