|
|
|
|
public void push(E obj) { /* ------------------------------- Check if stack is full ------------------------------- */ if ( t == S.length() - 1 ) { /* ----------------------------------- Stack full: double the stack space ------------------------------------ */ A = (E[]) new Object[S.length() * 2]; // 2 x space for ( i = 0; i <= S.length() - 1; i++ ) A[i] = S[i]; // Copy old array over S = A; // Set new array } /* --------------------------- The actual push operation --------------------------- */ ++t; // Next element S[t] = obj; // Store it } |
|
|
(However, the worst case happens rarely !!!)
|
Conclusion:
|
|
|
|
|
Conclussion:
|
|
We have then under-estimated the average run time requirement !!!