Linked List Problem


Problem statement

Write a Java program that, given a linked list of characters, removes all Nodes with info 'A' from the list. All remaining elements must appear in their original order.

As shown in the test cases below, your code may assume that the Node reference variables head and tail are initialized to the first and last nodes of the linked list, respectively, or to null when the linked list is empty. Note that one additional reference variable p is declared. For this exercise, you may not declare any additional variable.
The method declaration is:
public void removeLetter(Node head)
Make sure that your code works on all possible linked lists. The following 9 test cases are provided to help you test your code.


Test case #1

Description: The linked list is empty.

Initial setup:

Final configuration:


Test case #2

Description: The linked list starts with a single 'A'.

Initial setup:

Final configuration:


Test case #3

Description: The linked list ends with a single 'A'.

Initial setup:

Final configuration:


Test case #4

Description: The linked list starts with several occurrences of 'A'.

Initial setup:

Final configuration:


Test case #5

Description: The linked list ends with several occurrences of 'A'.

Initial setup:

Final configuration:


Test case #6

Description: The linked list is made up of a single 'A'.

Initial setup:

Final configuration:


Test case #7

Description: The linked list only contains multiple occurrences of 'A'.

Initial setup:

Final configuration:


Test case #8

Description: The linked list contains no occurrences of 'A'.

Initial setup:

Final configuration:


Test case #9

Description: Random general case.

Initial setup:

Final configuration: