Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions