Skip to content
Battistella Stefano edited this page Apr 24, 2014 · 31 revisions

In computer science, a stack is a particular kind of abstract data type or collection in which the principal (or only) operations on the collection are the addition of an entity to the collection, known as push and removal of an entity, known as pop. The relation between the push and pop operations is such that the stack is a Last-In-First-Out (LIFO) data structure. In a LIFO data structure, the last element added to the structure must be the first one to be removed. This is equivalent to the requirement that, considered as a linear data structure, or more abstractly a sequential collection, the push and pop operations occur only at one end of the structure, referred to as the top of the stack.

Wikipedia

To create a stack you could use

Methods

getIterator()

This method returns an iterator for scanning the stack. The iterator is useful in order to get a full decoupling in your classes. This avoid, to the class that use the iterator, to know what type of data structure store the data.

var stack = new Stack();
var it = stack.getIterator();
for(it.first(); !it.isDone(); it.next()) {
var item = it.getItem();
//do something
}

The iterator starts from the top of the stack.

Clone this wiki locally