LinkedList low level implementaion [ii]
Problem statement: LinkedList low level implementation in java !
- class Node {
- Node next;
- int data;
- }
- public class LinkedListLowLevelExe2 {
- public static void main(String[] args) {
- Node head = new Node();
- head.next = null;
- head.data = 1;
- Node h2 = new Node();
- h2.next = null;
- h2.data = 2;
- Node h3 = new Node();
- h3.next = null;
- h3.data = 5;
- Node h4 = new Node();
- h4.next = null;
- h4.data = 8;
- Node h5 = new Node();
- h5.next = null;
- h5.data = 9;
- head.next = h2;
- h2.next = h3;
- h3.next = h4;
- h4.next = h5;
- h5.next = null;
- System.out.print(head.data + "-->"); // head.data
- System.out.print(head.next.data + "-->"); // head = head.next; head.data
- System.out.print(head.next.next.data + "-->"); // head = head.next.next; head.data
- System.out.print(head.next.next.next.data+"-->"); // head = head.next.next.next; head.data
- System.out.print(head.next.next.next.next.data); // head = head.next.next..next.next; head.data
- }
- }
Output:
1-->2-->5-->8-->9
Comments
Post a Comment