Linked List Code
form at nonsanity.com
Wed Apr 27 14:45:49 EDT 2011
Linked lists use pointers to allow the memory for the items to be allocated
as needed, and ties those pointers to each item for the next (and previous
for doubly-linked) so traversal code can hop from memory pocket to memory
pocket in the right order.
Whereas an array in a language like C keeps all the items in sequential
memory locations so moving form one to the next is just a matter of adding
one to the pointer to the current item.
In LiveCode, memory allocation and management is handled by the system.
The old-school method of handling lists (and one I still use when order is
most important) is the good old comma-delimited list. Inserting and deleting
is done with the "put x before/after" command or the "delete item x"
command. Access it direct by item number.
put "A,B,C,D,E,F" into myList
delete item 5 of myList
put ",3" after item 2 of myList
put item 4 of myList into msg -- "C"
put item 2 to -2 of myList into msg -- "B,3,C,D"
put myList into msg -- "A,B,3,C,D,F"
You can also use arrays, though if you are deleting items, you need to
access the list of keys. This can get more complex, since LC's arrays are
~ Chris Innanen
On Sun, Apr 24, 2011 at 8:08 PM, Pete <pete at mollysrevenge.com> wrote:
> By chance, does anyone have an LC script for handling a linked list
> (navigating, inserting, deleting)?
> Molly's Revenge <http://www.mollysrevenge.com>
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
More information about the Use-livecode