Stack |
ICloneable | |
ICollection | |
IEnumerable | |
IObject | |
IVersionable |
Name | Description |
---|---|
Count (get) | Gets the number of elements contained in the Stack. |
Name | Description |
---|---|
Clear | Removes all items from the Stack. |
Clone | Creates a shallow copy of the Stack. |
Contains | Determines whether an element is in the Stack. |
CopyTo | Copies the Stack to an existing one-dimensional array, starting at the specified array index. |
Equals | Determines whether the specified value is equal to the current object. |
GetEnumerator | Returns an enumerator to enumerate the colleciton |
GetHashCode | Returns a pseudo-unique number identifying this instance. |
Peek | Returns the item at the top of the Stack without removing it. |
Pop | Removes and returns the item at the top of the Stack. |
Push | Inserts an item at the top of the Stack. |
ToArray | Copies the Stack to a new array. |
ToString | Returns a string representation of this object instance. |
The capacity of a Stack is the number of elements the Stack can hold. As elements are added to a Stack, the capacity is automatically increased as required through reallocation.
If Count is less than the capacity of the stack, Push is an O(1) operation. If the capacity needs to be increased to accommodate the new element, Push becomes an O(n) operation, where n is Count. Pop is an O(1) operation.
The following example shows how to create and add values to a Stack and how to print out its values.
Public Sub Main() ' Creates an initializes a new Stack. Dim MyStack As New Stack MyStack.Push "Hello" MyStack.Push "World" MyStack.Push "!" ' Displays the properties and values of the Stack. Debug.Print "MyStack" Debug.Print vbTab & "Count: " & MyStack.Count Debug.Print vbTab & "Values:"; PrintValues MyStack End Sub Private Sub PrintValues(ByVal MyCollection As IEnumerable) Dim Item As Variant For Each Item In MyCollection Debug.Print " " & Item; Next Debug.Print End Sub ' This example code produce the following output. ' ' MyStack ' Count: 3 ' Values: ! World Hello