School of Biomedical Engineering Jimma Institute of Technology Jimma University
School of Biomedical Engineering Jimma Institute of Technology Jimma University
FINAL LABORATORY #2
SIMULATE THE OPERATION OF THE STACK ADT
Prepared by:
The actions push, pop, peek, empty, and size are simply translated into specifications for
methods called push(), pop(), peek(), isEmpty(), and size(). These are the standard names for
stack operations. Each method is specified by describing its return value as well as any
modifications it makes to the object.
3. The Stack interface may be implemented in a variety of ways. The most basic method is to
utilize an ordinary array. The ArrayStack implementation stores stack components in an array
a[]. Its other data field is the number top, which corresponds to the stack's top member. The
top is also used to tally the number of things currently in the stack. Create a new Java class and
name it ArrayStack to implement this stack interface. java.
4. Write the following code on your java class:
public class ArrayStack implements Stack
{
private Object a[];
private int top;
public ArrayStack(int n)
{
a = new Object[n];
top = -1;
}
Simulation of Stack
Main Menu
Options:
[1] Push an Item
[2] Pop an Item
[3] Exit the Program
Choice: ____
PuM 3 PoM
3 2 1 1 2 3
SSI PI SSI