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 23 → 47.25 → 86, 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: 23 → 35.5 → 47.25 → 86 Step 3: Test in develop mode Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList. The list is displayed after each insertion. Ex: If input is 77 15 -42 63.5 then output is: List after inserting 77: 77 List after inserting 15: 15 77 List after inserting -42: -42 15 77 List after inserting 63.5: -42 15 63.5 77 Try various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the remove() method 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 84 72 19 61 19 84 then output is: List after inserting 84: 84 List after inserting 72: 72 84 List after inserting 19: 19 72 84 List after inserting 61: 19 61 72 84 List after removing 19: 61 72 84 List after removing 84: 61 72

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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 23 → 47.25 → 86, 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: 23 → 35.5 → 47.25 → 86

Step 3: Test in develop mode

Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList. The list is displayed after each insertion. Ex: If input is

77 15 -42 63.5

then output is:

List after inserting 77: 77 List after inserting 15: 15 77 List after inserting -42: -42 15 77 List after inserting 63.5: -42 15 63.5 77

Try various program inputs, ensuring that each outputs a sorted list.

Step 4: Implement the remove() method

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

84 72 19 61 19 84

then output is:

List after inserting 84: 84 List after inserting 72: 72 84 List after inserting 19: 19 72 84 List after inserting 61: 19 61 72 84 List after removing 19: 61 72 84 List after removing 84: 61 72

 

List Labs X
← → CO
=zyBooks
Course Mo X zy Section 4.1 x b My Questio
x G Step 1: Ins X
✰ learn.zybooks.com/zybook/GERMANNACSC223 Medina-DeVilliers Fall2023/chapter/4/section/18
My library > CSC 223: Data Structures and Analysis of Algorithms home >
4.18: LAB: Sorted number list implementation with linked lists
LabProgram. Java
File is marked as read only
1 public class Node {
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
protected double data;
protected Node next;
protected Node previous;
Node. Java and SortedNumberlist.java
public Node (double initialData) {
data = initialData;
next = null;
previous = null;
Current file: Node.java →
Stacks and X
Develop mode
// Constructs this node with the specified numerical data value. References to the next
// and previous nodes are assigned null.
public Node (double initialData, Node nextNode, Node previousNode) {
data = initialData;
next
nextNode;
Submit mode
Stacks and
Download
X
}
// Constructs this node with the specified numerical data value, references to the next
// and previous nodes.
zyBooks catalog
Stacks and
x +
? Help/FAQ
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
second box.
X
Ibrahim Raza
:
All Bookmarks
Transcribed Image Text:List Labs X ← → CO =zyBooks Course Mo X zy Section 4.1 x b My Questio x G Step 1: Ins X ✰ learn.zybooks.com/zybook/GERMANNACSC223 Medina-DeVilliers Fall2023/chapter/4/section/18 My library > CSC 223: Data Structures and Analysis of Algorithms home > 4.18: LAB: Sorted number list implementation with linked lists LabProgram. Java File is marked as read only 1 public class Node { 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 protected double data; protected Node next; protected Node previous; Node. Java and SortedNumberlist.java public Node (double initialData) { data = initialData; next = null; previous = null; Current file: Node.java → Stacks and X Develop mode // Constructs this node with the specified numerical data value. References to the next // and previous nodes are assigned null. public Node (double initialData, Node nextNode, Node previousNode) { data = initialData; next nextNode; Submit mode Stacks and Download X } // Constructs this node with the specified numerical data value, references to the next // and previous nodes. zyBooks catalog Stacks and x + ? Help/FAQ Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. X Ibrahim Raza : All Bookmarks
List Labs X
← → CO
= ZyBooks
Course Mo X zy Section 4.1 x b My Questio
x G Step 1: Ins X
✰ learn.zybooks.com/zybook/GERMANNACSC223 Medina-DeVilliers Fall2023/chapter/4/section/18
My library > CSC 223: Data Structures and Analysis of Algorithms home >
4.18: LAB: Sorted number list implementation with linked lists
LabProgram.java
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
tail = null;
}
// Optional: Add any desired private methods here
}
Node. Java and SortedNumberlist.java
// Inserts the number into the list in the correct position such that the
// List remains sorted in ascending order.
public void insert (double number) {
// Your code here
public boolean remove (double number) {
// Your code here
return false;
Stacks and X
Current file: SortedNumberList.java
Develop mode
}
// Removes the node with the specified number value from the list. Returns
// true if the node is found and removed, false otherwise.
Submit mode
Stacks and
Download
X
Stacks and
x +
zyBooks catalog ? Help/FAQ
Load default template...
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
second box.
:
All Bookmarks
Ibrahim Raza
Transcribed Image Text:List Labs X ← → CO = ZyBooks Course Mo X zy Section 4.1 x b My Questio x G Step 1: Ins X ✰ learn.zybooks.com/zybook/GERMANNACSC223 Medina-DeVilliers Fall2023/chapter/4/section/18 My library > CSC 223: Data Structures and Analysis of Algorithms home > 4.18: LAB: Sorted number list implementation with linked lists LabProgram.java 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 tail = null; } // Optional: Add any desired private methods here } Node. Java and SortedNumberlist.java // Inserts the number into the list in the correct position such that the // List remains sorted in ascending order. public void insert (double number) { // Your code here public boolean remove (double number) { // Your code here return false; Stacks and X Current file: SortedNumberList.java Develop mode } // Removes the node with the specified number value from the list. Returns // true if the node is found and removed, false otherwise. Submit mode Stacks and Download X Stacks and x + zyBooks catalog ? Help/FAQ Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. : All Bookmarks Ibrahim Raza
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education