Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to write the ArrayStack problem in Java !!!!!! thanks ArrayStack.java This class implements a stack using an array. The header for this class must

How to write the ArrayStack problem in Java !!!!!!

thanks

image text in transcribedimage text in transcribedimage text in transcribed

ArrayStack.java This class implements a stack using an array. The header for this class must be this: public class ArrayStack implements ArrayStackADT This class will have the following private instance variables: TI stack. This array stores the data items of the stack. . O . int top. O This variable stores the position of the last data item in the stack. In the constructor this variable must be initialized to -1, this means the stack is empty. Note that this is different from the way in which the variable top is used in the lecture notes. O This class will have the following public static variable: public static String sequence; Used for tracking the arrow path. . o This class needs to provide the following public methods: . O ArrayStack() Creates an empty stack. The default initial capacity of the array used to store the items of the stack is 14 (for Valentine's day) O ArrayStack(int initialCapacity). Creates an empty stack using an array of length equal to the value of the parameter. O 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(); } O o T pop() throws EmptyStackException Removes and returns the data item at the top of the stack. An EmptyStackException is thrown if the stack is empty. 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; 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. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions