LinkedList low level implementaion [ii]

Problem statement: LinkedList low level implementation in java !
  1. class Node {
  2. Node next;
  3. int data;
  4. }

  5. public class LinkedListLowLevelExe2 {
  6. public static void main(String[] args) {

  7. Node head = new Node();
  8. head.next = null;
  9. head.data = 1;

  10. Node h2 = new Node();
  11. h2.next = null;
  12. h2.data = 2;

  13. Node h3 = new Node();
  14. h3.next = null;
  15. h3.data = 5;

  16. Node h4 = new Node();
  17. h4.next = null;
  18. h4.data = 8;

  19. Node h5 = new Node();
  20. h5.next = null;
  21. h5.data = 9;

  22. head.next = h2;
  23. h2.next = h3;
  24. h3.next = h4;
  25. h4.next = h5;
  26. h5.next = null;

  27. System.out.print(head.data + "-->"); // head.data
  28. System.out.print(head.next.data + "-->"); // head = head.next; head.data
  29. System.out.print(head.next.next.data + "-->"); // head = head.next.next; head.data
  30. System.out.print(head.next.next.next.data+"-->"); // head = head.next.next.next; head.data
  31. System.out.print(head.next.next.next.next.data); // head = head.next.next..next.next; head.data
  32. }
  33. }
Output:
1-->2-->5-->8-->9

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation