Creating Dynamic Data structures (from FLWS)

Source: Internet
Author: User
creating Dynamic Data structures.
In the ' This series- Creating custom Collections-I showed to wrap the A. NET collection class to create a new enumerable collection with a custom name. In that article I used a ArrayList as my underlying storage container. Is that a good choice? Should I have used a HashTable? What ' s the difference anyway?
As you are probably aware, there are many differences between a HashTable and a ArrayList, but what Eady know is this this differences can dictate how the underlying data are stored in memory. In this article I ' ll explain the different structures which are used to store data in memory and demonstrate why collection classes require different underlying structures.
What are collections
Collections are structures that allow programs to store and retrieve the items of data in a various structured. The standard. NET collections include:
· Hashtable
· ArrayList
· Stack
· Queue
An important feature of collections are that this total number of items this they contain is (generally) unknown until Me, i.e.: Each of the item is added to a collection the actual structure this houses the data is altered.
Dynamic Vs. Static Data Storage
Many data Structures-such as Int32 and Arrays-are static. This means the their structure is completely defined in design time. While the field ValuesOf these structures can is altered by the program, the structure itself cannot.
DYNAMIC data structures allow their structure to by altered through the actual program, and because of this, they are ideal can Didates to act as the underlying storage container for the items of a collection. A dynamic data structure that underlies a collection can expand or contract as items are added or removed from the list.
Two examples of common dynamic data structures are linked lists and binary.
linked List
Without going into any great depth, a linked list is a list of items; Each item is, itself a structure, and contains a value and a pointer (or reference) to the next item in the list. Adding a new item to a linked list simply means creating a new instance of ' an ' and adding a reference to it ' I The TEM is currently at the tail of the list.
The following snippet of Psuedo-code shows how to might create a linked list of Fish, and then graphically displays That structure would look like:
Class myfishes
Public Property Headfish as Fish
Public Property Tailfish as Fish

Public method Addfish (Newfish as Fish)

If isnothing (me.headfish) Then
Me.headfish = Newfish
Me.tailfish = Newfish
Else
Me.TailFish.NextFish = Newfish
Me.tailfish = Newfish
End If
End method
End Class

Class Fish
Public Property Name as String
Public Property Nextfish as Fish
End Class

Dim thelistoffishes as New myfishes ()

Thelistoffishes.addfish (New Fish ( "Fred.") )
Thelistoffishes.addfish (New Fish ( "Martin") )
Thelistoffishes.addfish (New Fish ( "Rob.") )
Thelistoffishes.addfish (New Fish ( "Karen.") )

+--------------------+
| thelistoffishes |
+--------------------+
|
+-----------------------------------+
| |
+--------+  +--------+  +--------+  +--------+
|  |        |  |        |  |        | |
| Fred |->|  Martin |->|  Rob |->| Karen |-> Nothing
|  |        |  |        |  |        | |
+--------+  +--------+  +--------+  +--------+

Note:the linked list contains a pointer with
A null reference
Use a linked list when it's important to retrieve items in a manner this is, relevant to, in which they Added to the list. Take the following Psuedo-code snippet which shows how to might normally retrieve these records from this type of STRUCTU Re

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.