0

I stumbled across this page : Create Linked List in AS3

Since AS3.0 is a scripting language. I wonder how come linked list is possible in AS3.0 ? Isn't pointer ( a way to access memory location ) mandatory to create a linked list. That ultimately makes array of data faster in performance ?

2 Answers 2

3

In AS3 you have object references, you don't have pointers exactly, but you can achieve a linked list using the references in a very similar way. The advantage of a Linked List (in general) is in insertion and deletion within the list (you don't have to shift all elements as in using an array). You still get this benefit using object references.

Note: Objects in AS3 are passed by reference, primitives are passed by value.

Sign up to request clarification or add additional context in comments.

Comments

2

Effectively all scripting languages do work with pointers.

They only decided to call them differently (most times they call them "references") and to hide the complexity (or even possibilities) of managing the memory allocation and releasing.

Having said that the simplest way to create a linked list in ActionScript (or JavaScript) would be

var node1 = {value: 1};
var node2 = {value: "foo"};
var node3 = {value: "bar"};

//of course this code should be localices within a separate class
//with some nice API
((node1.next = node2).next = node3).next = null;

//and then use like that e.g.
var n = node1;
while (n) {
    trace(n.value);
    n = n.next;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.