Skip to content

Instantly share code, notes, and snippets.

@jingz8804
Created July 19, 2014 02:20
Show Gist options
  • Save jingz8804/bf526d7c7406705873bf to your computer and use it in GitHub Desktop.
Save jingz8804/bf526d7c7406705873bf to your computer and use it in GitHub Desktop.
#intuit
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