LinkedList low level implementation [iv]

Problem statement: LinkedList low level implementation in java !

  1. class Node2 {
  2. Node2 next;
  3. int data;

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

  8. public class LinkedListLowLevelExe4 {
  9. public static void main(String[] args) {
  10. Node2 head = new Node2(4);
  11. Node2 h2 = new Node2(5);
  12. Node2 h3 = new Node2(6);
  13. Node2 h4 = new Node2(8);

  14. head.next = h2;
  15. h2.next = h3;
  16. h3.next = h4;
  17. h4.next = null;
  18. print(head);
  19. }

  20. public static void print(Node2 next) {
  21. Node2 temp = next;
  22. while (temp != null) {
  23. System.out.print(temp.data + "-->");
  24. temp = temp.next;
  25. }
  26. }
  27. }

Output:
4-->5-->6-->8-->

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation