Macromedia Director Developer Articles
|
|
|

Coding in lingo
  Sorting Multidimensional Lists
  Binary Search
  Building an efficient table
Director Quirks

Sorting Multidimensional Lists
 
October.12.2003

Lingo provides the function arrary.sort() to sort any one dimensional array quickly, but what do you do when you want to sort an array that contains more than 1 dimension? This article describes the use of the merge sort algorithm to sort multidimensional lists. Merge sort is fairly efficient because it uses the divide and conquer method to break up a list and sorts it using pointer arithmetic. The runtime is 0(n log n), which makes this algorithm idea for lingo developers who still use methods such as a double repeat loop to sort multidimensional lists.

The source code is available for download. Comments, suggestions, errors are always welcomed.

Creating a small searching algorithm
 
October.5.2003

You're working with a ordered list that contains 1000 (stings), first names, . How do you find "jonh" in this list? At first glance, using the the lingo command getPos, array.getPos("john") could be sufficient, but there are 2 problems with using getPos. First of all, what if there's more than 1 person named john? Secondly getPos was implemented against all that you've learned about in Director. That is, getPos actually use case sensitive search. This means that "John" and "john" are not going to yield the same result. If your only option is to write a repeat loop that traverses from item 1 to 1000, then you need to read this article on how to improve your search algorithm. For comparison purposes, this article describes how you can write an algorithm that can compare a 30,000 item list with just 14 comparisons.

Building an efficient table
 
October.5.2003

Product Cost
Nikon 5700
999.99
Canon G5
799.99
FujFilm FinePix S5000
499.99
Sony Cybershot DSC-V1
699.99
Pentax Optio S
399.9

How do you implement a data structure resembling this table? One way of building a data structure is create something like this: myPropList = [ [#product: "Nikon 5700", #cost: 999.99], [#product: "Canon G5 ", #cost: 799.99], [#product: "Fujifil FinePix S5000 ", #cost: 499.99], .... ]. The advantage of using property list lies in the readability of your code, but the disadvantage of using property lists is the tremendous waste of memory to store the property name for each row. This article describes how to build an efficient table object and use algorithms from the last 2 articles to improve performance.

 

 
© Calu. All rights reserved.
Page last modified on October 7, 2004