Class TStack
TStack class
TStack implements a stack. The typical stack operations are implemented, which include push(), pop() and peek(). In addition, contains() can be used to check if an item is contained in the stack. To obtain the number of the items in the stack, check the Count property. Items in the stack may be traversed using foreach as follows, - foreach($stack as $item) ...
Constructor Summary |
public |
Constructor.
|
Method Summary |
void
|
Removes all items in the stack.
|
boolean
|
|
void
|
Copies iterable data into the stack.
|
integer
|
Returns the number of items in the stack.
|
integer
|
|
Iterator
|
Returns an iterator for traversing the items in the stack.
|
mixed
|
Returns the item at the top of the stack.
|
mixed
|
Pops up the item at the top of the stack.
|
void
|
Pushes an item into the stack.
|
array
|
|
Methods Inherited From TComponent |
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
Constructor Details |
__construct
Constructor.
Initializes the stack with an array or an iterable object.
Throws:
TInvalidDataTypeException If data is not null and neither an array nor an iterator.
|
Method Details |
clear
Removes all items in the stack.
|
contains
public boolean contains |
(mixed $item ) |
Input |
mixed | $item | the item |
Output |
boolean
| whether the stack contains the item |
Exception |
|
copyFrom
public void copyFrom |
(mixed $data ) |
Copies iterable data into the stack.
Note, existing data in the list will be cleared first.
Input |
mixed | $data | the data to be copied from, must be an array or object implementing Traversable |
Output |
Exception |
throws | TInvalidDataTypeException If data is neither an array nor a Traversable. |
|
count
Returns the number of items in the stack.
This method is required by Countable interface.
Output |
integer
| number of items in the stack. |
Exception |
|
getCount
public integer getCount |
() |
Output |
integer
| the number of items in the stack |
Exception |
|
getIterator
public Iterator getIterator |
() |
Returns an iterator for traversing the items in the stack.
This method is required by the interface IteratorAggregate.
Output |
Iterator
| an iterator for traversing the items in the stack. |
Exception |
|
peek
Returns the item at the top of the stack.
Unlike pop(), this method does not remove the item from the stack.
Output |
mixed
| item at the top of the stack |
Exception |
throws | TInvalidOperationException if the stack is empty |
|
pop
Pops up the item at the top of the stack.
Output |
mixed
| the item at the top of the stack |
Exception |
throws | TInvalidOperationException if the stack is empty |
|
push
public void push |
(mixed $item ) |
Pushes an item into the stack.
Input |
mixed | $item | the item to be pushed into the stack |
Output |
Exception |
|
toArray
Output |
array
| the list of items in stack |
Exception |
|
|