Posts

Showing posts from May, 2022

Linked List in Java without Collections

Linked List in Java without Collections class Node { int data ; Node next ; Node ( int data) { this . data = data ; this . next = null; } } public class Main { public static void main (String[] args) { Node n1 = new Node( 5 ) ; Node n2 = new Node( 6 ) ; Node n3 = new Node( 7 ) ; Node n4 = new Node( 8 ) ; n1. next = n2 ; n2. next = n3 ; n3. next = n4 ; Node start = n1 ; while (start!= null ) { System. out .println(start. data + " " ) ; start = start. next ; } } }