Question: X 9 7 5 : Build Two Nodes Using this class definition: 1 public class node { 2 / / . . . instance variables

X975: Build Two Nodes
Using this class definition:
1
public class node {
2
//... instance variables
3
public node(E d, node n){
4
this.data = d;
5
this.next = n;
6
}
7
public E getData(){return data; }
8
public void setData(E d){data = d; }
9
public node getNext(){return next; }
10
public void setNext(node n){next = n; }
11
}
Complete the method build2Nodes that creates two objects of type node, and places the values of the a and b parameters in these nodes. The first node (a) should have its next field point to the second node created (b). The method should return the head of the list created, that is the pointer to the node with the value in a.
Your Answer:
1
public node build2Nodes(E a, E b)
2
{
Using this class definition:
1
public class node {
2
//... instance variables
3
public node(E d, node n){
4
this.data = d;
5
this.next = n;
6
}
7
public E getData(){return data; }
8
public void setData(E d){data = d; }
9
public node getNext(){return next; }
10
public void setNext(node n){next = n; }
11
}
Complete the method createNewNode that returns a new node using the constructor above.
Your Answer:
1
public node createNewNode(E a)
2
{

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 Programming Questions!