Skip to content

Latest commit

 

History

History
48 lines (38 loc) · 929 Bytes

Ex_1_3_33.md

File metadata and controls

48 lines (38 loc) · 929 Bytes
title date draft tags categories
Algorithm4 Java Solution 1.3.33
2019-07-04 05:47:10 +0800
false
JAVA
TECH
archives

1.3.33

Problem:

Deque. A double-ended queue or deque (pronounced “deck”) is like a stack or a queue but supports adding and removing items at both ends. A deque stores a collection of items and supports the following API:

Solution:

refer to code.

// LinkedBlockingDeque
    private E unlinkFirst() {
        // assert lock.isHeldByCurrentThread();
        Node<E> f = first;
        if (f == null)
            return null;
        Node<E> n = f.next;
        E item = f.item;
        f.item = null;
        f.next = f; // help GC
        first = n;
        if (n == null)
            last = null;
        else
            n.prev = null;
        --count;
        notFull.signal();
        return item;
    }

Reference:

java: LinkedBlockingDeque