Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Linked list
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example of internal and external storage=== To create a linked list of families and their members, using internal storage, the structure might look like the following: '''record''' ''member'' { ''// member of a family'' ''member'' next; ''string'' firstName; ''integer'' age; } '''record''' ''family'' { ''// the family itself'' ''family'' next; ''string'' lastName; ''string'' address; ''member'' members ''// head of list of members of this family'' } To print a complete list of families and their members using internal storage, write: aFamily := Families ''// start at head of families list'' '''while''' aFamily β '''null''' ''// loop through list of families'' print information about family aMember := aFamily.members ''// get head of list of this family's members'' '''while''' aMember β '''null''' ''// loop through list of members'' print information about member aMember := aMember.next aFamily := aFamily.next Using external storage, the following structures can be created: '''record''' ''node'' { ''// generic link structure'' ''node'' next; ''pointer'' data ''// generic pointer for data at node'' } '''record''' ''member'' { ''// structure for family member'' ''string'' firstName; ''integer'' age } '''record''' ''family'' { ''// structure for family'' ''string'' lastName; ''string'' address; ''node'' members ''// head of list of members of this family'' } To print a complete list of families and their members using external storage, write: famNode := Families ''// start at head of families list'' '''while''' famNode β '''null''' ''// loop through list of families'' aFamily := (family) famNode.data ''// extract family from node'' print information about family memNode := aFamily.members ''// get list of family members'' '''while''' memNode β '''null''' ''// loop through list of members'' aMember := (member)memNode.data ''// extract member from node'' print information about member memNode := memNode.next famNode := famNode.next Notice that when using external storage, an extra step is needed to extract the record from the node and cast it into the proper data type. This is because both the list of families and the list of members within the family are stored in two linked lists using the same data structure (''node''), and this language does not have parametric types. As long as the number of families that a member can belong to is known at compile time, internal storage works fine. If, however, a member needed to be included in an arbitrary number of families, with the specific number known only at run time, external storage would be necessary.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)