void add(ListNode cur) { ListNode lastp = tail.prev; lastp.next = cur; cur.next = tail; tail.prev = cur; cur.prev = lastp; }
public Solution(int capacity) { // write your code here this.capacity = capacity; len = 0; head = new ListNode(0, 0); tail = new ListNode(0, 0); head.next = tail; tail.prev = head; hash = new HashMap<Integer, ListNode>(); }
public void addFirst(Object a) { ListNode tmp = new ListNode(a); tmp.next = head.next; tmp.prev = head; head.next = tmp; }
public void addLast(Object a) { ListNode tmp = new ListNode(a); tmp.prev = tail; tail.next = tmp; tail = tmp; }
void delete(ListNode cur) { ListNode lastp = cur.prev; ListNode nextp = cur.next; lastp.next = nextp; nextp.prev = lastp; }