| MrOmega |
11-03-2010 04:51 AM |
SortBubble( array, collation)
Well, redid this script and used the bubble method of sorting, simple to understand.
parameter:
1st - Array to Sort
2nd - Collation to use, if NULL it will use AlphaNumeric Collation
Script:
PHP Code:
function sortBubble( temp.list, temp.order)
{
if ( !temp.order)
{
temp.order =
{
"`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(",
")", "-", "_", "=", "+", "[", "{", "]", "}", "|", ";",
":", ",", "<", ".", ">", "/", "?", "0", "1", "2", "3",
"4", "5", "6", "7", "8", "9", "A", "a", "B", "b", "C",
"c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h",
"I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N",
"n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s",
"T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y",
"y", "Z", "z"
};
}
for ( temp.a = 0; temp.a < ( temp.list.size() ^ 2); temp.a ++)
{
if ( temp.swap)
{
temp.a =
temp.swap = NULL;
}
if ( (temp.a + 1) == temp.list.size())
break;
while ( temp.obj1 == temp.obj2)
{
temp.obj1 = ( @ temp.list[ temp.a]).substring( temp.start, 1);
temp.obj2 = ( @ temp.list[ temp.a + 1]).substring( temp.start, 1);
temp.start ++;
if (( @ temp.list[ temp.a]) == ( @ temp.list[ temp.a + 1]))
break;
}
if ( temp.order.index( temp.obj1) > temp.order.index( temp.obj2))
{
temp.swap = temp.list[ temp.a];
temp.list[ temp.a] = temp.list[ temp.a + 1];
temp.list[ temp.a + 1] = temp.swap;
}
temp.obj1 =
temp.obj2 =
temp.start = NULL;
}
return temp.list;
}
Usage:
PHP Code:
sortBubble( {"a", "0", "aa", "a", "How", "Now", "Brown", "Cow", "?", "A", "a"})
would give you this
PHP Code:
{"?","0","A","a","a","a","aa","Brown","Cow","How","Now"}
|