Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. public class List {
  2. private Node head;
  3.  
  4. public List() {
  5. head = null;
  6. }
  7.  
  8. public void add(Node x) {
  9. if (head == null) {
  10. head = x;
  11. }
  12.  
  13. else {
  14. Node current = head;
  15. while (x.getNext() != null) {
  16. current = x.getNext();
  17. }
  18. // chegaste ao fim
  19. current.setNext(x);
  20. }
  21. }
  22.  
  23. public static void main(String[] args) {
  24. Node n1 = new Node(1);
  25. System.out.println(n1.getValue());
  26. System.out.println(n1.getNext());
  27. List l1 = new List();
  28. l1.add(n1);
  29.  
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement