From Book: Data Abstraction and Problem Solving using Java; Ch 7; Problem 12 add
ID: 3540410 • Letter: F
Question
From Book: Data Abstraction and Problem Solving using Java; Ch 7; Problem 12
addition to the standard stack operations%u2014isEmpty, push, pop, and peek %u2014 a traversable stack includes the operation traverse. The traverse operation is an iterator that begins at the bottom of the stack and displays each item in the stack until it reaches the top of the stack. Alternatively, you could create a StackIterator class based on the StackInterface, as given in Chapter 7. However, the iterator would then only have access to the methods contained in the interface, such as push, pop, and peek. Since the iterator should not change the contents of the stack,
the implementation would be quite inef%uFB01cient.
The StackIterator class would be more ef%uFB01cient if it had access to the under-
lying stack implementation (either StackArrayBased or StackReferenceBased).
Implement a Stack class within a package that provides package access to the stack%u2019s
underlying data structure. Then, in the same package, create a StackIterator class
that uses this new Stack class.