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;
}
}
}

Comments

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.