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"};
for (var a:int = 1; a < 4 ; a++)
{
if (a < 3)
{
node[a].next = node[a + 1];
}
else
{
node[a].next = null;
}
}
// ((node1.next = node2).next = node3).next = null; works, but
// not 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 ?
i know object is not an array, but it should be possible to get the pointer on the right position. I am pretty sure, that could be a dynamic solution. I really tried different notation. Do you have a hint for me ?
node1asthis['node' + a]ifais1. However I don't understand what you are trying to achieve