Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. class Node {
  2. public int data;
  3. public Node next;
  4.  
  5. public Node(int _data, Node _next) {
  6. data = _data;
  7. next = _next;
  8. }
  9. }
  10.  
  11. public class NodeClient {
  12. public static void main(String[] args) {
  13. Node a = new Node(10, null);
  14. Node b = new Node(70, a);
  15. Node c = new Node(20, null);
  16. Node d = new Node(90, c);
  17. Node e = new Node(30, d);
  18. c.next = b;
  19. System.out.println("a holds value "+a.data);
  20. System.out.println("b holds value "+b.data);
  21. System.out.println("c holds value "+c.data);
  22. System.out.println("d holds value "+d.data);
  23. System.out.println("e holds value "+e.data);
  24. System.out.println("node after b (that is a) holds value "+b.next.data);
  25. System.out.println("node after c (that is b) holds value "+c.next.data);
  26. System.out.println("node after d (that is c) holds value "+d.next.data);
  27. System.out.println("node after e (that is d) holds value "+e.next.data);
  28. System.out.println("node after the node after e (that is c) holds value "+e.next.next.data);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement