Java Reference
In-Depth Information
A
BSTRACT
D
ATA
T
YPE
: S
TACK
D
ATE
•
A collection of objects in reverse chronological order and having the same data type
O
PERATIONS
P
SEUDOCODE
UML
D
ESCRIPTION
push(newEntry)
+push(newEntry: T): void
Task: Adds a new entry to the top of the
stack.
Input:
newEntry
is the new entry.
Output: None.
pop()
+pop(): T
Task: Removes and returns the stack's top
entry.
Input: None.
Output: Returns either the stack's top entry
or, if the stack is empty before the
operation,
null
.
peek()
+peek(): T
Task: Retrieves the stack's top entry without
changing the stack in any way.
Input: None.
Output: Returns either the stack's top entry
or, if the stack is empty,
null
.
isEmpty()
+isEmpty(): boolean
Task: Detects whether the stack is empty.
Input: None.
Output: Returns true if the stack is empty.
clear()
+clear(): void
Task: Removes all entries from the stack.
Input: None.
Output: None.
Note:
Alternate names for methods
It is not unusual for a class designer to include aliases for certain methods. For example, you
could include the additional methods
add
and
remove
(or
insert
and
delete
) in the ADT
stack to mean
push
and
pop
. Moreover,
pull
is sometimes used to mean
pop
, and
getTop
can
mean
peek
, so including them as aliases is reasonable.