Link

Programming

Manipulating linked lists and getting familiar with JUnit tests.

Table of contents

  1. Implementation
    1. firstToLast
    2. extend
    3. concatenated
  2. Running Tests

Implementation

This homework assignment consists of implementing three methods for the LinkedIntList class. All the graded tests are provided to you in the LinkedIntListTest class.

Take a look around the LinkedIntList class before you begin programming. We’ve provided a couple examples: three ways of squaring all of the items in a list. Understanding these examples will help when it comes to solving the problems in this assignment. Try using the Java Visualizer to display the state of the program as it runs.

firstToLast

Implement a method, void firstToLast(LinkedIntList L), that moves the first element of the list L to the back end of the list.

LinkedIntList L: front → 18 → 4 → 27 → 9 → 54 → 5 → 63 → /
 firstToLast(L): void
              L: front → 4 → 27 → 9 → 54 → 5 → 63 → 18 → /

If the list is empty or has just one element, its contents should not be modified.

extend

Implement a method, void extend(LinkedIntList A, LinkedIntList B), that adds all of the items in B to the end of A without using the new keyword or creating new nodes.

LinkedIntList A: front → 1 → 2 → 3 → /
LinkedIntList B: front → 4 → 5 → 6 → /
   extend(A, B): void
              A: front → 1 → 2 → 3 → 4 → 5 → 6 → /
              B: front → 4 → 5 → 6 → /

concatenated

Implement a method, LinkedIntList concatenated(LinkedIntList A, LinkedIntList B), that is similar to extend but rather than modifying A instead returns a new list that contains all of the items in A followed by all of the items in B. Don’t modify A or B; use the new keyword to create new nodes.

   LinkedIntList A: front → 1 → 2 → 3 → /
   LinkedIntList B: front → 4 → 5 → 6 → /
concatenated(A, B): front → 1 → 2 → 3 → 4 → 5 → 6 → /
                 A: front → 1 → 2 → 3 → /
                 B: front → 4 → 5 → 6 → /

Running Tests

Run the tests in the LinkedIntListTest class to check your work, as described in the Using IntelliJ page.

For this assignment, the tests on Gradescope are the same tests you can run in IntelliJ. In later assignments, we’ll be emphasizing testing as a skill, so some tests may only be available on Gradescope and you may be limited in the frequency of submissions you can make.

Visit the Commit & Submit page for instructions on saving your work and submitting it for grading.