Write a push method for a stack implemented with an array. You may assume that the stack is referenced by an array named stack, and that there is an integer variable named count that keeps track of the number of elements in the stack. You may not assume that you have access to an expandCapacity method, nor should your code throw an exception if the stack is full. Your method should include code to expand the capacity of the array if it is full.
What will be an ideal response?
```
public void push(T element) {
if(count == stack.length) {
T[] newStack = new T[stack.length*2];
for(int i = 0; i < stack.length; i++)
newStack[i] = stack[i];
stack = newStack;
}
stack[count++] = element;
}
```
Computer Science & Information Technology
You might also like to view...
To position text within a table in the center of its cell, click both the Center button and the ________ button on the Layout tab
Fill in the blank(s) with correct word
Computer Science & Information Technology
Expression Web can be used to create and edit HTML files; however, you need a separate CSS editor to create and edit the related CSS files.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology