简体   繁体   English

java.util.Stack 和 java.util.ArrayDeque 中的 grow() 方法之间的区别

[英]difference between the grow() methods in java.util.Stack and java.util.ArrayDeque

I came across the grow() method for when a stack is full, but when I saw there was a difference in the grow() function in the arraydeque, I wondered what the difference actually was.当堆栈已满时,我遇到了 grow() 方法,但是当我看到 arraydeque 中的 grow() function 存在差异时,我想知道实际差异是什么。

Does anyone know the answer to this?有谁知道这个问题的答案?

if (s == elementData.length){
    elementData = this.grow()
}

So eventually I found out that the differences are the following:所以最终我发现差异如下:

Stack growable:堆栈可增长:

  1. Tight Strategy: Add a constant amount to the old stack (N+c)紧的策略:向旧堆栈添加一个常数(N+c)
  2. Growth Strategy: Double the size of old stack (2N)增长策略:旧堆栈大小翻倍(2N)

Arraydeque growable: Arraydeque 可增长:

'Array deques have no capacity restrictions and they grow as necessary to support usage.' “数组双端队列没有容量限制,它们会根据需要增长以支持使用。” arraydeque 数组队列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM