' This program demonstrates using a linked list as a substitute for array in type.
' *****************************
' *** TYPEs and Definitions ***
' *****************************
FriendList
AS SoftArrayStructure
' - Stores a Label for human readability.
' - Stores a LONG integer to denote place in memory.
' *******************************
' *** Populate regular values ***
' *******************************
Steve.NickName = "SMcNeill"
Steve.Country = "USA"
' Nothing new so far, right? Confusion level: zero
' **************************
' *** Create linked list ***
' **************************
Steve.FriendList.HeadNode = NewSoftArray("Steve's Friends")
' This line initializes a linked list ^, and stores the head node address in Steve.FriendList.HeadNode.
' Note we have not specified the size, the data it holds, etc.
' The head node address is calculated automatically - think of it like an image handle.
' ********************************
' *** Structure of linked list ***
' ********************************
' Now we populate Steve's list of friends. The end result is going to look like:
'
' Steve's Friends ------- Friend 1 (Joe)
' |
' Friend 2 (Tom)
' |
' Friend 3 (Biff)
'
' Note that "Friend 1" appears to the "East" of the Label.
' Note that "Frinds 2" appears to the "South" of Friend 1.
' Note that "Frinds 3" appears to the "South" of Friend 2.
' ****************************
' *** Populate linked list ***
' ****************************
' Define a helper variable to keep the notation slim:
a = Steve.FriendList.HeadNode
a = LinkEast(a, NewTextNode("Joe"))
a = LinkSouth(a, NewTextNode("Tom"))
a = LinkSouth(a, NewTextNode("Biff"))
' ... And that's it. The data is stored according to the structure above.
' Each piece of data is stored in a Node, each with its own address.
' The name of the game now is getting used to handling these addresses.
' *************************
' *** Print linked list ***
' *************************
' The following line will print the entire list, including the head node.
PRINT PrintSoftArray
("Steve's Friends")
' ************************************
' *** Retrieve first piece of data ***
' ************************************
' The very first item on the list can be printed by:
PRINT Literal$
(Content
("Steve's Friends"))
' ************************
' *** Typical FOR loop ***
' ************************
FOR j
= 0 TO Bottom
("Steve's Friends") PRINT Literal$
(JumpFrom
(Content
("Steve's Friends"), "s", j
))
REM $Include: 'SoftArrays.bm'