Data Structures: Stacks and Queues


Stacks. A stack is a collection that is based on the last-in-first-out (LIFO) policy. By tradition, we name the stack insert method push() and the stack remove operation pop(). We also include a method to test whether the stack is empty, as indicated in the following API:

Video Lectures :
Stacks and Queues
Clients
Assignment:
Implement the ArrayStackOfIntegers ADT for Integers using arrays.
Other members that you need to implement:
import java.util.Iterator;
import java.util.NoSuchElementException;
public class ArrayStackOfIntegers implements Iterable {
private Integers[] items; // holds the items
private int n; // number of items in stack
public ArrayStackOfIntegers(int capacity) {
items = (Integer[]) new Object[capacity];
}
public boolean isEmpty() {
----
}
public boolean isFull() {
----
}
public void push(Integer item) {
----
}
public Integer pop() {
}
public Iterator iterator() {
return new ReverseArrayIterator();
}
// an iterator, doesn't implement remove() since it's optional
private class ReverseArrayIterator implements Iterator {
----
public void remove()
{}
}
}
The files in this site are cleaned up a bit here.
Use the ArrayStackOfIntegers ADT to work on these assignments:
ArrayStackOfIntegers ADT – Calculator
Design and implement a client to calculate the following postfix expression: 8 4 -3 * 1 5 + / *
ArrayStackOfIntegers ADT – Enhanced Calculator
StackCalculatorEnhanced
