Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class List {
- private Node head;
- public List() {
- head = null;
- }
- public void add(Node x) {
- if (head == null) {
- head = x;
- }
- else {
- Node current = head;
- while (x.getNext() != null) {
- current = x.getNext();
- }
- // chegaste ao fim
- current.setNext(x);
- }
- }
- public static void main(String[] args) {
- Node n1 = new Node(1);
- System.out.println(n1.getValue());
- System.out.println(n1.getNext());
- List l1 = new List();
- l1.add(n1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement