国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Creating dynamic data structures(from flws)

2024-07-21 02:22:06
字體:
來源:轉載
供稿:網友
creating dynamic data structures.
in the first part of this series - creating custom collections - i showed how to wrap a .net collection class to create a new enumerable collection with a custom name. in that article i used an arraylist as my underlying storage container. was that a good choice? should i have used a hashtable? what's the difference anyway?
well, as you are probably aware, there are many differences between a hashtable and an arraylist, but what you may not already know is that these differences can dictate how the underlying data is stored in memory. in this article i'll explain the different structures that are used to store data in memory and demonstrate why different collection classes require different underlying structures.
what are collections
collections are structures that allow programs to store and retrieve various items of data in a structured manner. the standard .net collections include:
·     hashtable
·     arraylist
·     stack
·     queue
an important feature of collections is that the total number of items that they contain is (generally) unknown until runtime, i.e.: each time an item is added to a collection the actual structure that houses the data is altered.
dynamic vs. static data storage
many data structures - such as int32 and arrays - are static. this means that their structure is completely defined at design time. while the field values of these structures can be altered by the program, the structure itself cannot.
dynamic data structures allow their structure to by altered by the actual program, and because of this, they are ideal candidates 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 trees.
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 item and adding a reference to it from the item that is currently at the tail of the list.
the following snippet of psuedo-code shows how you might create a linked list of fish, and then graphically displays what 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 last child in a linked list contains a pointer with
      a null reference
you use a linked list when it is important to retrieve items in a manner that is relevant to the order in which they were added to the list. take the following psuedo-code snippet which shows how you might normally retrieve these records from this type of structure: 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九台市| 松潘县| 德昌县| 沙坪坝区| 什邡市| 来宾市| 大姚县| 新龙县| 靖远县| 县级市| 澎湖县| 芷江| 潞西市| 衡山县| 井陉县| 长春市| 九寨沟县| 凌云县| 潍坊市| 四平市| 旅游| 阜康市| 临湘市| 慈溪市| 临颍县| 宾阳县| 阳东县| 靖江市| 朝阳市| 潮安县| 辉县市| 黄山市| 石河子市| 吴旗县| 扬州市| 中方县| 体育| 南召县| 察雅县| 色达县| 安龙县|