home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************
- ADOBE SYSTEMS INCORPORATED
- Copyright 2002 Adobe Systems Incorporated
- All Rights Reserved
-
- NOTICE: Adobe permits you to use, modify, and distribute this
- file in accordance with the terms of the Adobe license agreement
- accompanying it. If you have received this file from a source
- other than Adobe, then your use, modification, or distribution
- of it requires the prior written permission of Adobe.
- ***************************************************************/
- /***************************************************************
- Author: Mary Obelnicki
- ***************************************************************/
-
- /***************************************************************
-
- Sort by comparing each adjacent pair of items in a list in turn,
- swapping the items if necessary, and repeating the pass through
- the list until no swaps are done.
-
- Arguments:
- <a> - an array of objects or values
- <property> - an optional argument. If <a> is an array of
- objects, this is the property for which the sort will
- be based upon.
-
- Example:
- var a = new Object();
- a.x = -5;
- var b = new Object();
- var c = new Object();
- c.x = 0;
- var d = new Object()
- d.x = 10;
-
- var testArray = new Array(d, c, b, a);
- bubbleSort(testArray, "x");
- var i;
- for(i = 0; i < testArray.length; i++)
- {
- Console.write(testArray[i].x + "\n");
- }
-
- ***************************************************************/
-
- /***************************************************************
- DO NOT EDIT BELOW THIS LINE
- ***************************************************************/
-
-
- function swap(a, i, j)
- /*
- a: the array in which to swap elements
- i, j: indexes of the elements to swap
- */
- {
- var t = a[i];
- a[i] = a[j];
- a[j] = t;
- }
-
- function bubbleSort(a, property)
- {
- var i, j;
- if(property == null)
- property = "";
- else
- property = "." + property;
- for(i = a.length-1; i>=0; i--)
- for(j = 1; j <= i; j++)
- {
- $.bp();
- if(eval("a[j-1]"+ property) > eval("a[j]"+property))
- swap(a, j-1, j);
- }
- }
-
-
-
-