Question: I need help with these 2 methods: IN JAVA ECLIPSE **public void push(T dataItem)** **public T pop() throws EmptyStackException** THE PRIVATE VARIABLES OF THIS CLASS

I need help with these 2 methods: IN JAVA ECLIPSE

**public void push(T dataItem)**

**public T pop() throws EmptyStackException**

I need help with these 2 methods: IN JAVA ECLIPSE **public void

push(T dataItem)** **public T pop() throws EmptyStackException** THE PRIVATE VARIABLES OF THIS

CLASS ARE: private T[] stack;// This array stores the data items of

the stack. private int top;//This variable stores the position of the last

THE PRIVATE VARIABLES OF THIS CLASS ARE:

private T[] stack;// This array stores the data items of the stack. private int top;//This variable stores the position of the last data item in the stack.

void push(T dataltem) o Adds dataltem to the top of the stack. If the array storing the data items is full, you will increase its capacity as follows: . If the capacity of the array is smaller than 50, then the capacity of the array will be increased by 10. . Otherwise, the capacity of the array will increase by doubling the initial size. So, if, for example, the size of the array is 225 and the array is full, when a new item is added the size of the array will increase to 450. At the end of this method, add the following. This is used in TestSearch to make sure you are following a correct path: if (dataltem instanceof MapCell) { sequence += "push" + ((MapCell)dataltem).getIdentifier(); } else { sequence += "push" + dataltem.toString(); } T pop() throws EmptyStackException o Removes and returns the data item at the top of the stack. An EmptyStackException is thrown if the stack is empty. o If after removing a data item from the stack the number of data items remaining is smaller than one fourth of the length of the array you need to shrink the size of the array by one half, to a minimum of 14; o To do this create a new array of size equal to half of the size (to a minimum of 14) of the original array and copy the data items there. o For example, if the stack is stored in an array of size 100 and it contains 25 data items, after performing a pop operation the stack will contain only 24 data items. Since 24

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!