|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractList | +--java.util.Vector | +--java.util.Stack | +--ExpressionElementStack
This is a simple extension of Stack
which is designed specifically
to hold ExpressionElements. The major additions are
nextElement()
which returns an ExpressionElement
as opposed the Object
that is usually returned. The same goes for top()
which adds the same typecasting
for Stack.peek()
.
Other functionality added was the capacity to reverse()
the elements in the stack
and to dump()
the information in the stack to System#out
.
Fields inherited from class java.util.Vector |
capacityIncrement,
elementCount,
elementData |
Fields inherited from class java.util.AbstractList |
modCount |
Constructor Summary | |
ExpressionElementStack()
|
Method Summary | |
void |
dump()
Prints the elements of the stack to java.lang.System#out . |
ExpressionElement |
nextElement()
Removes the top element from the stack and returns it |
void |
reverse()
Reverses the order of the elements in the stack. |
ExpressionElement |
top()
Check the top element from the stack and returns it; the top remains on the stack. |
Methods inherited from class java.util.Stack |
empty,
peek,
pop,
push,
search |
Methods inherited from class java.util.Vector |
add,
add,
addAll,
addAll,
addElement,
capacity,
clear,
clone,
contains,
containsAll,
copyInto,
elementAt,
elements,
ensureCapacity,
equals,
firstElement,
get,
hashCode,
indexOf,
indexOf,
insertElementAt,
isEmpty,
lastElement,
lastIndexOf,
lastIndexOf,
remove,
remove,
removeAll,
removeAllElements,
removeElement,
removeElementAt,
removeRange,
retainAll,
set,
setElementAt,
setSize,
size,
subList,
toArray,
toArray,
toString,
trimToSize |
Methods inherited from class java.util.AbstractList |
iterator,
listIterator,
listIterator |
Methods inherited from class java.lang.Object |
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public ExpressionElementStack()
Method Detail |
public ExpressionElement nextElement()
public ExpressionElement top()
public void reverse()
- n = the size of the stack
- i = 1
- while i < n - i
- swap elements i and n - i
- i = i + 1
ArithmeticEquation.ArithmeticEquation(java.lang.String)
for example.) A stack is
a First In Last Out structure and what is needed
sometimes is a Last In Last Out structure. In order
to get one I could either create a new queue type or add this method to stack.
This was by far the more efficient solution.public void dump()
java.lang.System#out
. Each element is
on its own line and includes the ExpressionElement.typeString()
and a
string representation of the element.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |