国产探花免费观看_亚洲丰满少妇自慰呻吟_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: 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 维西| 定南县| 高邑县| 晋宁县| 厦门市| 东阿县| 阳江市| 仙桃市| 罗城| 万荣县| 古蔺县| 麦盖提县| 平顶山市| 拉孜县| 日喀则市| 灌阳县| 新兴县| 深水埗区| 正定县| 那曲县| 色达县| 汝南县| 凤翔县| 满洲里市| 竹北市| 长汀县| 昌吉市| 阜阳市| 罗田县| 嘉定区| 奎屯市| 常宁市| 五峰| 秦皇岛市| 民勤县| 张家界市| 镇平县| 民乐县| 札达县| 札达县| 财经|