frost.collections

Class Stack<T>

    └ Object

Implemented Interfaces:

An implementation of the stack abstract data type. A stack is a collection of elements which operates in "LIFO" (last in, first out) order; that is, the element most recently added to the stack is the first one retrieved.

Source Code:
View Source

Field Summary

count:Int
The number of elements on the stack.
Inherited Fields:

Instance Method Summary

push(v:T)
Pushes a new element onto the stack.
pop():T
Pops the top value from the stack and returns it.
insert(depth:Int, value:T)
Inserts a new element at the specified depth.
removeIndex(depth:Int):T
-- index operator --
[](depth:Int):T
Returns the value at the given depth in the stack.
clear()
Removes all elements from the stack.

Fields

property count:Int

The number of elements on the stack.

Instance Methods

method push (v:T)

Pushes a new element onto the stack.

Parameters:
v - value of type T
@pre(count > 0)
method pop ():T

Pops the top value from the stack and returns it.

method insert (depth:Int,
 value:T)

Inserts a new element at the specified depth. A depth of 0 is equivalent to push.

Parameters:
depth - value of type Int
value - value of type T
method removeIndex (depth:Int
):T
Parameters:
depth - value of type Int
-- index operator --
@pre(depth >= 0 & depth < count)
function [] (depth:Int
):T

Returns the value at the given depth in the stack. The top element (most recently pushed) is element 0, and the bottom element (earliest pushed) is element count - 1.

Parameters:
depth - value of type Int
method clear ()

Removes all elements from the stack.