What is a data structure that has O(1) for append, prepend, and retrieve element at any location?
问题 I'm looking for Java solution but any general answer is also OK. Vector/ArrayList is O(1) for append and retrieve, but O(n) for prepend. LinkedList (in Java implemented as doubly-linked-list) is O(1) for append and prepend, but O(n) for retrieval. Deque (ArrayDeque) is O(1) for everything above but cannot retrieve element at arbitrary index. In my mind a data structure that satisfy the requirement above has 2 growable list inside (one for prepend and one for append) and also stores an offset