Fandom

Visual Basic Wiki

How to implement a stack using a Collection

66pages on
this wiki
Add New Page
Talk0 Share

First, create a Collection and add a dummy element to it:

Set C = New Collection
C.Add Null

Then, add elements to your stack like this:

C.Add E, , 1

To see what's on the top of the stack:

C(1)

To remove the item on the top of the stack:

C.Remove 1

You might ask why not to implement a stack the other way around. The reason is twofold: readability and performance. When implemented this way, the code is much simpler to read. If you implement a stack the other way around, you will find that although adding elements is slightly faster, due to the implementation of the Collection class removing them takes a lot longer, on the order of the number of elements on the stack.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.