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

168 Views Asked by At

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.

Does anyone know the answer to this?

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

There are 1 best solutions below

0
On BEST ANSWER

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)
  2. Growth Strategy : Double the size of old stack (2N)

Arraydeque growable:

'Array deques have no capacity restrictions and they grow as necessary to support usage.' arraydeque