Guest User

Untitled

a guest
Oct 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. package list;
  2.  
  3. /**
  4.  *
  5.  * @author Dmitry Kankalovich, 2011
  6.  */
  7. public class List<T> {
  8.     private Node head;
  9.     private Node tail;
  10.    
  11.     private class Node {
  12.         public T obj;
  13.         public Node next;
  14.        
  15.         public Node(T obj) {
  16.             this.obj = obj;
  17.         }
  18.     }
  19.    
  20.     public void add(T obj) {
  21.         if(head == null) {
  22.             head = new Node(obj);
  23.             tail = head;
  24.         } else {
  25.             Node current = head;
  26.             while(current.next != null) {
  27.                 current = current.next;
  28.             }
  29.            
  30.             current.next = new Node(obj);
  31.             tail = current.next;
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment