Question: Implement Singly LinkedList and test the correctness of your program. 1. UML class diagram of class Node Node element: Object next: Node + Node(Object element,

Implement Singly LinkedList and test the correctness of your program.

1. UML class diagram of class Node

Node

element: Object

next: Node

+ Node(Object element, Node next)

+ getElement(): Object

+ getNext(): Node

+ setElement(Object element): void

+ setNext(Node next): void

2. UML class diagram of class SLL

SLL
head: Node

+ SLL()

+ getHead(): Node

+ setHead(Node head): void

+ print(): void // output all elements in SLL

+ add(Node n): void // add the node n after the old tail node so that it becomes the tail node

+ remove(): void // remove the tail node

+ reverse(): void // reverse the Singly LinkedList

+ main(String[] args): void // test

3. Testing cases:

Create Nodes a (element = 1), b (element = 2), c (element = 3)

Create SLL s

Print all elements in s // output nothing

Add a, b, c to s, and then print all elements in s // output 1, 2, 3

Remove, and then print all elements in s // output 1, 2

Remove, and then print all elements in s // output 1

Remove, and then print all elements in s // output nothing

Add a, b, c to s, and then print all elements in s // output 1, 2, 3

Reverse s, and then print all elements in s // output 3, 2, 1

Embed your java files Node.java and SLL.java in the box below.

4. Add more features to class SLL, and design testing cases to test them by yourself (you may need them for future project).

Add a method in SLL to search whether it contains an element x

Add a method in SLL to return the index i of element x

Add a method in SLL to add a node at index i

Add a method in SLL to remove the node at index i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!