X977: Build Nodes

Using this class definition:

public class node<E> {
  //... instance variables
  public node(E d, node<E> n) {
    this.data = d;
    this.next = n;
  }
  public E getData() {return data; }
  public void setData(E d) {data = d; }
  public node<E> getNext() {return next; }
  public void setNext(node<E> n) {next = n; }
}

As a more general form of building nodes, this method takes an array of values and creates as many nodes as there are objects in the values array. This method returns the node that has the values[0]. The head node next points to values[1], and so forth.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.