Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

18.0 Points Create a wave class called Specialist. This class will be a singly linked data structure composed of LinearNode objects (see the attached Linear

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
18.0 Points Create a wave class called Specialist. This class will be a singly linked data structure composed of LinearNode objects (see the attached Linear Node class). Each list will be given a dividing fine" (let's call it 'd') such that elements less than d are on the left side of the list and elements greater than d are on the right side. The elements should not be sorted completely but must be divided to the two sides of the list Whenever an element is added to the list, it must be compared to d to see which side of the list is should be added to fit less than a the element must be added at the front of the list so that it becomes the new front. If it greater than d add the item to the end of the list so that it becomes the last element of the list. We can assume that elements will never be equal tod for simplicity The class must have the following 2 instance variables you may NOT change or add any instance variables); private LinearNodecinteger front private int : The class must have a constructor which takes in a parameter d with which you must initialize the instance variable d Initialize front as null. The class mus also have a getter method getFront() to return the front pointer. The most important method of this class is addToList (Integer element) in which you must perform the main task of determining which side of the list to add the new element to, based on the value of a. You also must create a new LinearNode_Integer containing the new element and then add it to the correct side of the existing list (either the very front or the very end). The front pointer must be correctly updated when necessary and the connections front rode to node must be correctly updated as well. Hint: there are multiple cases to consider, te the very first element vs. a new element The method signature for this method must be: public void addToList (Integer element) Linear Node.java 1 KB Tesi specialistjava 1 KB (55) You de represents and in a list Puthor or Lewis on loro Linde te irrect next Britt ein: Create an empty rode e Lineartede - 11 tuli 2 Ceeates a node storing the specified element. Para eles the element to be stored within the new node * public Linear Modele) next elentele - Returns the node that follow this one. return the not that follows the current pulte Linear Hodect getext() return neti sets the node that follow this one para note the nose to be set to follow the current one public void settiext (narodet node) next node Returns the element stored in this mode return the element stored in this rode Creates a node storing the specified element. - on eles the element to be stored within the new node puthar Node (Eelen) telen Returns the pode that follows this one. return the node that follows the current one public Linear flodec> cetNext() return next; 2 Sets the node that follows this one. param node the node to be set to follow the current one public void setNext (Linear Nodec node) next node 2 Returns the element stored in this node. return the element stored in this node public t getElement() return element; 2 Sets the element stored in this node. para eles the element to be stored in this node public void settlement (i elen) element - elem OWL: Home : Overview public Test Specialist public static string orintist Socialist 1) Lineartedecinteger cure the fronto String while ( ) strerettlement(). : Curr - cupr.test(); 1 return str > public static void main(string) args) Specialisti Integer Integer()); Integer y teper() System.out.println(*): // Test si-new Specialist (0) 31. AddTollst (4) 1.ToList 2) sladdfolist(-5) sladdToList(-1): 31.addToList(-7); $1.addtollit()); String sprinttist(s); if (sl.equals(-7 -1 5 4 2 3 >> System.out.println("Test 1 Passed), 2 eise System.out.println("Test 1 Toiled": 1/ Test 2 31 - Specialist (6) si addToList(5): 51.addToList (13) sl addrolist(25); s1.addToList (41) si.addrolist (12) sl. addToList (17) s1.addrolist (7): 51.addrolist(0); si addToList (24) $1.addToList(); String s2 - printList(51) 1 (s.equals(3.07 5 13 25 41 12 17 24 >> System.out.println("Test 2 Passed"); y else System.out.println("Test 2 Failed"); 51. AddToListas: String printit (1) if (t.equals(-71 -5 4 2 3 >> System.out.printing Test 1 Passed) else System.out.println("Test 1 Folled"); W. Test 2 sl new Specialist (8) 31. addToList(5); sladdToList (13) sl.addToList(25); sl addToList (41); si adatoList (12) sl.addTol ist(17), sl.addToList (7): sl. addToList(e) sl.addToList (24) s1.addToList(3); String 52 - printList(61) 1F (52.equals(" @ 7.5 13 25 41 12 17 24 ")) { System.out.println("Test 2 Passed" else System.out.println("Test 2 Failed 17 Test 3 $1 = new Specialist(5); sladdToList(1); sl.addToList(9) $1.addToList(6): si.adaTolist(3); sl.addToList(11); sl.addToList (15); s1.addfolist(2); st. addToList(-5); String 53 - printuist(s); 11 (3.equals("$ 2 3 1 96 11 15 ")) { System.out.println("Test 3 Passed"); } else System.out.printin("Test 3 Falled"); } me Overview (35) Vi Create a Java class called Specialist. This class will be a singly linked data structure composed of LinearNode objects (see the attached LinearNode class). Each list will be given a "dividing line" (let's call it'd') such that elements less than d are on the left side of the list and elements greater than d are on the right side. The elements should not be sorted completely but must be divided to the two sides of the list. Whenever an element is added to the list, it must be compared to d to see which side of the list is should be added to. If it less than d, the element must be added at the front of the list so that it becomes the new front. It it greater than d, add the item to the end of the list so that it becomes the last element of the list. We can assume that elements will never be equal to d for simplicity The class must have the following 2 instance variables (you may NOT change or add any instance variables): private LinearNode d The method signature for this method must be: public void addToList (Integer element) LineatNode.java 1 KB

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

Students also viewed these Databases questions