Guest User

Untitled

a guest
Aug 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class Node<T>
  2. {
  3. private T info;
  4. private Node<T> next;
  5.  
  6. public Node(T x)
  7. {
  8. this.info = x;
  9. this.next = null;
  10. }
  11. public Node(T x, Node<T> next)
  12. {
  13. this.info = x;
  14. this.next = next;
  15. }
  16. public Node<T> getNext()
  17. {
  18. return this.next;
  19. }
  20. public void setNext(Node<T> next)
  21. {
  22. this.next = next;
  23. }
  24.  
  25. public T getInfo()
  26. {
  27. return this.info;
  28. }
  29. public void setInfo(T x)
  30. {
  31. this.info = x;
  32. }
  33. public String toString()
  34. {
  35. return this.info.toString();
  36. }
  37.  
  38. public void printChain() {
  39. System.out.println("The chain is:");
  40. Node<T> pos=this;
  41. while (pos!=null) {
  42. if (pos.getNext()==null) System.out.print(pos);
  43. else System.out.print(pos+" -->");
  44. pos=pos.getNext();
  45. }
  46. System.out.println();
  47. }
  48.  
  49.  
  50. }
Add Comment
Please, Sign In to add comment