LinkedList low level implementation [iii]

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

  4. Node1(int data) {
  5. this.data = data;
  6. }
  7. }

  8. public class LinkedListLowLevelExe3 {
  9. public static void main(String[] args) {
  10. Node1 head = new Node1(2);
  11. Node1 h2 = new Node1(5);
  12. Node1 h3 = new Node1(6);
  13. Node1 h4 = new Node1(3);
  14. Node1 h5 = new Node1(9);

  15. head.next = h2;
  16. h2.next = h3;
  17. h3.next = h4;
  18. h4.next = h5;
  19. h5.next = null;

  20. System.out.print(head.data + "-->");
  21. System.out.print(head.next.data + "-->");
  22. System.out.print(head.next.next.data + "-->");
  23. System.out.print(head.next.next.next.data + "-->");
  24. System.out.print(head.next.next.next.next.data+"-->NULL");
  25. }
  26. }

Output:
2-->5-->6-->3-->9-->NULL

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation