Tuesday, May 1, 2018

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

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...