Why typical Array List implementations aren't double-ended?

前端 未结 4 1693
离开以前
离开以前 2020-12-11 18:47

Why aren\'t ArrayLists generally implemented to be double-ended, which would support fast amortized insertion in the front as well as the back?

Is there

4条回答
  •  有刺的猬
    2020-12-11 19:11

    A deque is used just when you want to access data in a FIFO or LIFO way, their common interface neither provide a way to obtain n-th element, you should do it by hand, and infact if you take a look at the Java Deque here, you understand that there is no n-th method provided. This should be enough to avoid its usage when you need to index any group of data.

    Ok, you can implement as an array deque instead that a normal array but this adds features that should be considered just when you need them, not by default. Otherwise you could justify using a more complex data structure for simple problems just because you can.

    IMHO it's also a matter of synergy between arrays nowadays and how they were implemented/managed when you wrote code nearer to the machine.

提交回复
热议问题