0
In addLastMethod loop is working infinite times please check once
2 Réponses
+ 3
You should be using a constructor within the LinkedList class to handle the internal class Node instantiation and this class should be private.
LinkedList.Node node1= L.new Node(1);
LinkedList.Node node2 =L. new Node(2);
LinkedList.Node node3 =L.new Node(4);
This way you won't create a circular reference to the same object at both ends of the LinkedList like you have when adding node3 twice. Once with addFirst then again with addLast. If you comment out either of those lines your print will work as expected.
L.addFirst(node1);
L.addFirst(node2);
L.addFirst(node3); // reference to node3 at head
L.addLast(node3); // reference to node3 at tail
node3
/ \
node1 <---- node2
https://code.sololearn.com/chWzlf68bxiz/?ref=app
https://code.sololearn.com/cCYegZHyKeAl/?ref=app
+ 1
Tysm