|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectap.ArrayStack
A simple yet completely functional implementation
of the Stack
interface. The interface
is part of the AP subset and is testable. This implementation
is not part of the subset, but is useful in
a classroom setting.
All stack functions execute in O(1) or constant time
amortized over several stack operations. This is because the
underlying storage is java.util.ArrayList
which
supports constant time access, add (to end), and remove
(from end).
This implementation is provided at apcentral.
Constructor Summary | |
ArrayStack()
Construct an initially empty stack. |
Method Summary | |
boolean |
isEmpty()
Returns true if this stack is empty, otherwise returns false. |
java.lang.Object |
peekTop()
Returns the top element of the stack without popping it. |
java.lang.Object |
pop()
Pops and returns the top element of the stack. |
void |
push(java.lang.Object x)
Push an element onto the top of this stack. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ArrayStack()
Method Detail |
public void push(java.lang.Object x)
Stack
push
in interface Stack
x
- is the object pushed onto this stack.public java.lang.Object pop()
Stack
pop
in interface Stack
Stack.peekTop()
public java.lang.Object peekTop()
Stack
peekTop
in interface Stack
Stack.pop()
public boolean isEmpty()
Stack
isEmpty
in interface Stack
|
unofficial documentation for the APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |