@Override
    public E set(int index, E element) {
        if (index < 0 || index > count) {
            throw new IndexOutOfBoundsException();
        }
        Node<E> aux = null;
        if (index < count / 2) {
            aux = header.next;
            for (int i = 0; i < index; i++) {
                aux = aux.next;
            }
        } else {
            aux = trailer.prev;
            for (int i = count - 1; i > index; i--) {
                aux = aux.prev;
            }
        }
        E elem = aux.element;
        aux.element = element;
        return elem;

    }