+ 1

How does the .nextnode points to the next node I'm confused here

public class Singly_linked_list { //Represent a node of the singly linked list class Node { int data; Node nextnode; Node(int data) { this.data = data; this.nextnode = null; } } //Represent the head and tail of the singly linked list public Node head = null; public Node tail = null; //addNode() will add a new node to the list public void addNode(int data) { //Create a new node Node newNode = new Node(data); //Checks if the list is empty if(head == null) { //If list is empty, both head and tail will point to new node head = newNode; tail = newNode; } else { //newNode will be added after tail such that tail's next will point to newNode tail.nextnode = newNode; //newNode will become new tail of the list tail = newNode; } }

27th May 2021, 3:25 PM
kreddyt
kreddyt - avatar
7 Respostas
+ 1
Martin Taylor i have a doubt are collections and data structures are same?
27th May 2021, 4:26 PM
kreddyt
kreddyt - avatar
+ 1
If yes I can't find singly and doubly linked list all i can find is only linked list
27th May 2021, 4:27 PM
kreddyt
kreddyt - avatar
+ 1
Thanks dude!! I felt frustrated to learn all of these in java!! Thx now I can rest in peace 💀
27th May 2021, 4:47 PM
kreddyt
kreddyt - avatar