17.4. Stacks


A stack is a last-in, first-out (LIFO) collection, like a stack of dishes at a buffet table, or a stack of coins on your desk. The last dish added to the top of the stack is the first dish you take off the stack.

The principal methods for adding to and removing from a stack are Push and Pop; Stack also offers a Peek method, very much like Queue. The significant methods and properties for Stack are shown in Table 17-4.

Table 17-4. Stack methods and properties

Method or property

Purpose

Count

Public property that gets the number of elements in the Stack

Clear

Removes all objects from the Stack

Clone

Creates a shallow copy

Contains

Determines if an element is in the Stack

CopyTo

Copies the Stack elements to an existing one-dimensional array

GetEnumerator

Returns an enumerator for the Stack

Peek

Returns the object at the top of the Stack without removing it

Pop

Removes and returns the object at the top of the Stack

Push

Inserts an object at the top of the Stack

ToArray

Copies the elements to a new array




Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net