Home CPSC 340

Lab 3: Linked List Exercise

 

Due: September 11


 

Objective

To gain practice using linked lists.


 

Task

For this lab, you will extend the LinkedList class with a couple of new methods.


 

Details


 

Testing

You can use the following main method to test your code:


public class ListMain {
    public static void main(String args[]) {
        // make a linked list of the letters A-Z
        LinkedList<Character> letters = new LinkedList<Character>();
        for (char c = 'A'; c <= 'Z'; c++) {
            letters.append(c);
        }

        // test the size
        System.out.println("There are " + letters.size() + " letters.");

        // test contains
        System.out.println("B: " + letters.contains('B'));
        System.out.println("X: " + letters.contains('X'));
        System.out.println("*: " + letters.contains('*'));

        // test get
        System.out.println("4: " + letters.get(4));
        System.out.println("15: " + letters.get(15));
        System.out.println("24: " + letters.get(24));

    }
}

The correct output for this lab, when you are finished, should be:

There are 26 letters.
B: true
X: true
*: false
4: E
15: P
24: Y

 

Submitting

When you are finished, please upload your code to the Canvas page for this assignment. Please send the .java file(s) only.

Copyright © 2020 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.