Tuesday, May 1, 2018

LinkedList low level implementation [i]

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

  5. public class LinkedListLowLevelExe1 {
  6. A head;

  7. public static void main(String[] args) {

  8. A1 head = new A1();
  9. head.data = 1;
  10. head.n = null;

  11. A1 h1 = new A1();
  12. h1.data = 2;
  13. h1.n = null;

  14. head.n = h1;

  15. A1 h2 = new A1();
  16. h2.data = 3;
  17. h2.n = null;

  18. h1.n = h2;

  19. A1 h3 = new A1();
  20. h3.data = 4;
  21. h3.n = null;

  22. h2.n = h3;

  23. A1 h4 = new A1();
  24. h4.data = 5;
  25. h4.n = null;

  26. h3.n = h4;
  27. System.out.println(head.data); // h.data;
  28. System.out.println(head.n.data); // h=h.n; h.data;
  29. System.out.println(head.n.n.data); // h=h.n.n;h.data;
  30. System.out.println(head.n.n.n.data); // h=h.n.n.n;h.data;
  31. System.out.println(head.n.n.n.n.data); // h=h.n.n.n.n;h.data;
  32. }
  33. }
Output:
1
2
3
4
5

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...