View Full Version : Linked List
stuckhere90
01-29-2008, 08:52 AM
How do you create a linked list in Open Laszlo? I just need to know how to start it. Does it use nodes? If so, how do you insert nodes into the list?
Thanks
AFAIK there isn't a built in linked list in OL.
I think you should look for a javascript linked list. LzNodes still do have overhead and are therefore slower to create.
kmeixner
02-06-2008, 09:07 AM
You could use a set of objects that have an attribute such as 'next' that point to the next object (ie: a linked list of objects) and then store this list in the attribute of another object or view.
Eg:
<class name="mynodeobj">
<attribute name="next" /><!-- Reference to next object-->
<method name="addNextObj" args="myNodeObj">
this.setAttribute('next', myNodeObj);
</method>
<method name="getNextObj">
return this.next;
</method>
</class>
<view name="linkedListContainer">
<attribute name="linkedlist" />
<method name="addNodeToEndOfLinkedList">
var newNode = new mynodeobj();
if (this.linkedlist == null){
// No items in linked list so we are adding 1st item:
this.setAttribute('linkedlist', newNode);
return; // nothing else to do
}
var currentNode = this.linkedlist; // grabs 1st node in list
while (currentNode.next != null){
// This will end up with final node in list
currentNode = currentNode.next;
}
currentNode.addNextObj(newNode);
</method>
</view>
The <view> has a 'addNodeToEndOfLinkedList()' method which can be used to add nodes to the end of the linked list. You can then add methods to traverse the list for items you are looking for etc., to get/edit the node, etc., whatever you want to do.
stuckhere90
02-06-2008, 11:37 AM
Thank you!
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.