Created
July 19, 2014 02:20
-
-
Save jingz8804/bf526d7c7406705873bf to your computer and use it in GitHub Desktop.
#intuit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DoublyLinkedList<T>{ | |
private class Node{ | |
T val; | |
Node next; | |
Node previous; | |
public Node(T val){ | |
this.val = val; | |
} | |
} | |
private Node head; | |
private Node tail; | |
private int N; // the size of the list | |
public void add(T val){ | |
Node n = new Node(val); | |
if(head == null){ | |
head = n; | |
tail = head; | |
}else{ | |
tail.next = n; | |
n.previous = tail; | |
tail = n; | |
} | |
N++; | |
} | |
public int size(){ | |
return N; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment