Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to keep what is given and only allowed to put java code in Your code here 4.18 LAB: Sorted number list implementation with

I have to keep what is given and only allowed to put java code in "Your code here"

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

4.18 LAB: Sorted number list implementation with linked lists Step 1: Inspect the Node.java file Inspect the class declaration for a doubly-linked list node in Node.java. Access Node.java by clicking on the orange arrow next to LabProgram.java at the top of the coding window. The Node class has three fields: - a double data value, - a reference to the next node, and - a reference to the previous node. Each field is protected. So code outside of the class must use the provided getter and setter methods to get or set a field. Node.java is read only, since no changes are required. Step 2: Implement the insert() method A class for a sorted, doubly-linked list is declared in SortedNumberList.java. Implement the SortedNumberList class's insert() method. The method must create a new node with the parameter value, then insert the node into the proper sorted position in the linked list. Ex: Suppose a SortedNumberList's current list is 2347.2586, then insert (33.5) is called. A new node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order and yielding: 2335.547.2586 Step 3: Test in develop mode Code in main0 takes a space-separated list of numbers and inserts each into a SortedNumberList. The list is displayed after each insertion. Ex: If input is 77154263.5 then output is: List after inserting 77 : 77 List after inserting 15 : 1577 List after inserting 42 : 421577 List after inserting 63.5 : 421563.577 Try various program inputs, ensuring that each outputs a sorted list. Implement the SortedNumberList class's remove() method. The method takes a parameter for the number to be removed from the list. If the number does not exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the number is removed from the list and true is returned. Uncomment the commented-out part in main() that reads a second input line and removes numbers from the list. Test in develop mode to ensure that insertion and removal both work properly, then submit code for grading. Ex: If input is 841972841961 then output is: List after inserting 84: 84 List after inserting 72: 7284 List after inserting 19: 197284 List after inserting 61: 1981 72 84 List after removing 19: 6172 84 List after removing 84: 6172 \begin{tabular}{l|l} LAB & 4.18.1: LAB: Sorted number list implementation with linked lists \\ ACTIVITY \end{tabular} Downloadable files File is marked as read only Current file: Node.java - public class SortedNumberList public Node head; public Node tail; public SortedNumberList() head = null; tail = null; \} // Optional: Add any desired private methods here // Inserts the number into the list in the correct position such that tr public void insert(double number) \{ /I Your code here \} // Removes the node with the specified number value from the list. Retur // true if the node is found and removed, false otherwise. public boolean remove(double number) \{ \} Your code here \} return false

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

Can knowledge workers and/or professionals be performance-managed?

Answered: 1 week ago

Question

Does a PMS enhance strategic integration within HRM?

Answered: 1 week ago