public void prioritize(T element) {
        final Iterator<T> iterator = deque.iterator();
        // Already prioritized? Then, do not reorder elements.
        for (int i = 0; i < numPriorityElements && iterator.hasNext(); i++) {
            if (iterator.next() == element) {
                return;
            }
        }
        // If the next non-priority element is the given element, we can simply include it in the
        // priority section
        if (iterator.hasNext() && iterator.next() == element) {
            numPriorityElements++;
            return;
        }
        // Remove the given element.
        while (iterator.hasNext()) {
            if (iterator.next() == element) {
                iterator.remove();
                break;
            }
        }
        addPriorityElement(element);
    }
@Test
    void testPrioritize() {
        final PrioritizedDeque<Integer> deque = new PrioritizedDeque<>();

        deque.add(0);
        deque.add(1);
        deque.add(2);
        deque.add(3);
        deque.prioritize(3);

        assertThat(deque.asUnmodifiableCollection()).containsExactly(3, 0, 1, 2);
    }