mercredi 28 septembre 2016

How to generate dynamic linked lists in actionscript 3

i am sitting on a problem. I am learning linked lists (beacuse i need this lateron for a tree solution) and try to create the links dynamically. Obviously i have the problem to generate the linkage between the objects.

Here is the Code

public function Main()
    {
        var node1:Object = {value: 1};
        var node2:Object = {value: "foo"};
        var node3:Object = {value: "bar"};
        var node4:Object = {value: "test"};
        var node:Object = {};

        for (var a:int = 1; a < 4 ; a++)
        {
            if (a < 3)
            {
            node[a].next = node1[a + 1];
            }
            else
            {
                node1[4].next = null;
            }

        }
        // ((node1.next = node2).next = node3).next = null; works, but 
        // not for the code above


        var n:Object = node1;
        while (n)
        {
            trace(n.value);
            var jsonString:String = JSON.stringify(n);
            trace(jsonString);

            n = n.next;
        }
    }

Can i have a explanation please ?

Aucun commentaire:

Enregistrer un commentaire