UT Linked Lists Project
Description
Download demo040522 from the class website. Create an Eclipse project using your
last name as part of the project name, say Murphylab9, and then copy files
SinglyLinkedList.java and TestSLL.java from that demo into your project.
File SinglyLinkedList.java contains definitions for a linked list of integers. The class
contains an inner class Node, which holds information for a single node in the list (a
node has a value and a reference to the next node). The SinglyLinkedList class
currently has the following methods:
1. public SinglyLinkedList() — constructor; creates an empty list of integers.
2. public void addFirst(int val) — takes an integer and puts it on the front of the list.
3. public boolean removeFirst() — removes the first value from the list and returns true if the
list contains at least one value. Returns false if the list is empty.
4. public void print() — prints the elements in the list from first to last.
5. public int addLast(int val) — takes an integer and puts it at the end of the list.
6. public boolean find (int target) – searches the list for a given target value
File TesSLL.java contains a driver that allows you to experiment with these methods.
Compile and run TestSLL, and play around with it to see how it works. Then add the
following methods to the SinglyLinkedList class. For each, add an option to the driver
to test it. Do this in incremental steps!! This means, implement and test the methods
one at a time.
1. public int size() — returns the number of elements in the list
2. public String toString() — returns a String containing the elements of the list within a pair
of square brackets and separated with a comma from each other.
3. public boolean removeLast() — removes the last element from the list and returns true. If
the list is empty, it returns false.
4. public void increment (int n) – increments each element of the list by the value of n,
where the value of n is read from the keyboard before the method is invoked.
5. public void printBackward() — prints the list elements starting from the last element
down to the first element. (Hint: Think recursively! The basic idea is to break up the list
into two parts: the first element, and a sub–list that contains the remaining elements. Print
the elements of the sub–list first, and then print the first element. The sub–list is the same
as the original list minus the first element so you can call the same method recursively to
print the elements of the sub–list. Note that printBackward() has no parameter so you
need to use a helper method that does most of the work. The helper method needs to
know where the sub–list starts, that means it takes a parameter of type Node.
private void printBackward(Node start) {}
Sample output: Your program output must show the results of running every option
on the menu.Programmer:type your name here!!!!!!Course:COSC 211, Winter22Project:lab #9Due date:4–7–22Menu====0: Quit1: Add an integer to the front of the list2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 6 0 Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward
Enter your choice: 1
Enter an integer to add to the front: 12
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward
Enter your choice: 1
Enter an integer to add to the front: 20
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 3
20 12
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 10
12 20
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 1
Enter an integer to add to the front: 100
Menu
==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 7
[100 , 20 , 12]
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 6
3
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 8
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."
6: Size of the list
7: Print the list returned by toString 8: Remove the last element from the list 9: Increment every element of the list by n 10: Print the list backward Enter your choice: 7
[100 , 20]
Menu ==== 0: Quit 1: Add an integer to the front of the list 2: Remove an integer from the front of the list
3: Print the list
4: Add an integer to the end of the list
5: Search for a target value in the list