Question: A. Create ArrayIntStack.java (one that's REALLY O(constant), totally!!!) B. Create the Javadoc web page (separate Assignment #15b). A. Create your own Stack Class , call

A. Create ArrayIntStack.java (one that's REALLY O(constant), totally!!!)

B. Create the Javadoc web page (separate Assignment #15b).

A. Create your own Stack Class, call it ArrayIntStack.java and write four public stack methods (this is the easy part of the assignment). Use at least one private helper method, to ensure capacity of the array. All other methods in your ArrayIntStack must have O(constant) run-time. Your ArrayIntStack extends no other Classes from the Java API. You must provide a default constructor.

1. boolean empty(); Tests if this stack is empty. 2. int peek(); Looks at the object at the top of this stack without removing it from the stack. 3. int pop(); Removes the object at the top of this stack and returns that object as the value of this function. 4. int push(int item); Pushes an item onto the top of this stack, return what was pushed.

5. private class IntStackIterator { // similar to what our author shows for the ArrayIntListIterator. 6. public IntStackIterator iterator() method so the client can browse through the data with .next() etc...

Since we're using int for return, you must throw an "appropriate" Exception (e.g. EmptyStackException) for illegal peek, pop, etc... operations. Regarding size, let's say this remains O(constant) while the Stack size is less than 20 elements, past that the push(int) would need to throw an Exception

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!