LinkedList low level implementation [v]

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

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

  8. public class LinkedListLowLevelExe5 {
  9. public static void main(String[] args) {

  10. Node3 head = new Node3(9);
  11. Node3 h2 = new Node3(2);
  12. Node3 h3 = new Node3(4);
  13. Node3 h4 = new Node3(5);
  14. Node3 h5 = new Node3(8);
  15. Node3 h6 = new Node3(9);

  16. // linking the obj reference with the next
  17. head.next = h2;
  18. h2.next = h3;
  19. h3.next = h4;
  20. h4.next = h5;
  21. h5.next = h6;
  22. // h6.next = null;

  23. print(head);

  24. }

  25. static void print(Node3 next) {
  26. Node3 temp = next;
  27. while (temp != null) {
  28. System.out.print(temp.data + "-->");
  29. temp = temp.next;
  30. }
  31. }
  32. }
Output:
9-->2-->4-->5-->8-->9-->

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation