Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
simDirectShow Xtra
CatFade
base64 encode/decode v1.2
DirectTransition
MediaMacros Devcon Presentation 2002 - Imaging Lingo
MPEG Xtra Simple Control
Rename for lingo animations
asUDP
AppActive
Drag Light-Alphamania
 

 

 

Behavior Bubble Sort for Points and Lists

Added on 6/30/1999

 

Compatibilities:
D6_5 D7 D8 Mac Script

This item has not yet been rated

Author: JamesNewton

Here"s a little handler that will sort points by either their locV (default) or their locH (if you use a non-void second parameter). On my Mac 7600/132, it reverses the order of a 1000 item list in less than 5 ticks, and reverses the order of a 100 item list in less that 1/5th of a tick. The principle can be adapted to sorting a list by any value (for example, the area of a rect). Have fun.

on bubbleSort pointList, horizontally
  -- SORTS VERTICALLY BY DEFAULT
  set horizontally = not voidP (horizontally)
  set pointCount = count (pointList)
  set bubble = TRUE
  repeat while bubble
    set i = pointCount -1
    set bubble = FALSE
    repeat while i
      if horizontally then
        set xLoc1 = the locH of getAt (pointList, i)
        set xLoc2 = the locH of getAt (pointList, i + 1)
      else
        set xLoc1 = the locV of getAt (pointList, i)
        set xLoc2 = the locV of getAt (pointList, i + 1)
      end if
      if xLoc1 > xLoc2 then
        set bubble = TRUE
        set xLoc1 = getAt (pointList, i)
        deleteAt pointList, i
        addAt pointList, i + 1, xLoc1
      end if
      set i = i - 1
    end repeat
  end repeat
  return pointList
end bubbleSort

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail