

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


public void remove(PositionedSceneElement node){ //Question 1 if (node==this){ System.out.println("I can't remove the first node from the list."); return; } //Question 2 PositionedSceneElement current = this; //Question 3 while (current.getNext() != null){ //Question 4 if (current.getNext() == node){ current.setNext(node.getNext()); node.setNext(null); return; } //Question 5 current = current.getNext(); } }
public class Element { private Element next; public Element getNext() {return this.next;} public void setNext(Element next) {this.next = next;} public int length() {return 0;} public static void main(String[]args){ Element node1 = new Element(); Element node2 = new Element(); Element node3 = new Element(); Element node4 = new Element(); node1.setNext(node2); node2.setNext(node3); node3.setNext(node4); node4.setNext(node1); System.out.println(node1.length()); } }