How To Implement a Linked List in Visual Basic (166394)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Control Creation Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
This article was previously published under Q166394 SUMMARY
The linked list, which is a classical data structure with widespread
applicability in C++, can also be implemented in Visual Basic with the use
of Classes.
A linked list is a set of items organized sequentially, just like an array.
In an array, the sequential organization is provided implicitly (by
position in the array); in a linked list, you use an explicit arrangement
in which each item is part of a "node" that also contains a "link" to the
next node.
The primary advantage of linked lists over arrays is that linked lists can
grow and shrink in size during their lifetimes. In particular, their
maximum size need not be known in advance. A secondary advantage is that
they provide flexibility in allowing the items to be rearranged efficiently
without actually moving any data contained in the list.
A disadvantage of a linked list is that operations such as referencing a
specific element in the list require you to walk the entire list from head
to tail. In an array, this could simply be done by accessing an (n).
Another operation that does not work with a linked list is finding an item
before a given item. To get around these limitations, you can build a
doubly-linked list in which two links for each node are maintained, one to
the item before and one to the item after. The cost of providing this extra
capability is doubling the number of link manipulations per basic
operation. This article will only demonstrate a simple linked list, not a
doubly-linked list.
REFERENCES
In Visual Basic Books Online see:
Programmer's Guide (All Editions)
Part 2: What Can You Do With Visual Basic
Programming With Objects
Creating Your Own Classes
Algoriths in C++, Robert Sedegwick, ISBN 0-201-51059-6
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Jon
Fowler, Microsoft Corporation
Modification Type: | Minor | Last Reviewed: | 7/1/2004 |
---|
Keywords: | kbhowto KB166394 |
---|
|