why is n1 not yield a null? I don’t understand the insert aftermethod. In newNode.next = next, is the next on the rhs referring ton1’s next?
public class Foothill
{
public static void main (String[] args)
{
Node n1, n2, n3, np;
n1 = new Node();
n2 = new Node();
n3 = new Node();
n1.insertAfter(n2); // insert n2 after n1
n2.insertAfter(n3); // insert n3 after n2
for (np = n1; np != null; np = np.getNext())
np.show();
}
}
//Class Node ———————————-
class Node
{
// data
private Node next;
// constructor
public Node()
{
next = null;
}
// console display
public void show()
{
System.out.print(“(generic node) “);
}
// insert after
public void insertAfter(Node newNode)
{
if (newNode == null)
return;
newNode.next = next;
next
PayPal Gateway not configured
PayPal Gateway not configured