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
- ***************************************************************/
-
- /***************************************************************
-
- A multipass, in-place sort algorithm which, on each pass, sorts
- i sets of n/i items, where n is the total number of items to sort.
- Originally the first increment was half the number of items to be
- sorted, i.e., n/2, and each succeeding increment was half the
- preceding increment.
-
- 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);
- shellSort(testArray, "x");
- var i;
- for(i = 0; i < testArray.length; i++)
- {
- Console.write(testArray[i].x + "\n");
- }
-
- ***************************************************************/
-
- /***************************************************************
- DO NOT EDIT BELOW THIS LINE
- ***************************************************************/
-
- function shellSort(a, property)
- /*
- sorts the array <a> using shell sort. Optionally, if the array
- contains objects, the objects can be sorted by <property>,
- a property of the objects.
-
- a: the array to sort
- property: if a is an array of Objects, the property the objects will
- be sort by. all objects must have this property to be sorted properly.
- */
- {
- if(property == null)
- property = "";
- else
- property = "." + property;
-
- var i, j, h, v;
- for(h = 1; (h *3 + 1 < a.length) ; h = 3*h+1);
- for( ; h > 0; h = Math.floor(h/3))
- {
- for(i = h; i < a.length; i++)
- {
- v = a[i];
- j = i;
- while(j>=h &&
- eval("a[j-h]"+property) > eval("v"+property))
- {
- a[j] = a[j-h];
- j -= h;
- }
- a[j] = v;
- }
- }
- }
-
-
-