push(Object o) -- add an element to the top of the stack
Object pop() -- remove an element from the top of the stack
Object peek() -- look at the element on the top of the
stack
boolean empty() -- check if the stack is empty
2 3 + 5 *.
2 3 5 * +
dc.
push(o) is just another name for insertAtFront(o)
pop() is just another name for removeFromFront()
peek() is just another name for head()
size() or length to
determine that.
enqueue(Object o) -- add an object to the back of the queue
Object dequeue() -- remove an object from the front of
the queue
Object front() -- determine what's at the front of the
queue, but don't remove it.
boolean empty() -- are there any elements in the queue?
public ArrayQueue {
/** The elements of the queue */
Object[] elements;
/** The index of the first element in the queue */
int first;
/** The index of the last element in the queue */
int last;
/** Add an element to the back of the queue */
public void enqueue(Object o) throws QueueException {
back = (back + 1) % elements.length;
elements[back] = o;
} // enqueue
/** Remove an element from the front of the queue */
public Object dequeue() throws QueueException {
Object returnme;
returnme = elements[front];
front = (front + 1) % elements.length;
return returnme;
} // dequeue
} // ArrayQueue
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Wed Oct 29 10:28:06 1997.
This page generated on Wed Nov 5 12:38:28 1997 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu