Hi,
I’m trying to sort a list of records with “numeric sort” for a field in this case age.
I would like that QuiskSort return me result as in the sample below. Any idea?
Ame
set ml to {{age:“20”, fullname:“John”}, {age:“8”, fullname:“Peter”}, {age:“1”, fullname:“Olaf”}, {age:“2”, fullname:“Ruby”}, {age:“10”, fullname:“Paul”}}
quickSortL(ml, 1, 3)
– return {{age:“1”, fullname:“Olaf”}, {age:“20”, fullname:“John”}, {age:“8”, fullname:“Peter”}, {age:“2”, fullname:“Ruby”}, {age:“10”, fullname:“Paul”}}
– should return {{age:“1”, fullname:“Olaf”}, {age:“2”, fullname:“Ruby”}, {age:“8”, fullname:“Peter”}, {age:“10”, fullname:“Paul”}, {age:“20”, fullname:“John”}}
on quickSortL(theList, theLeft, theRight)
set i to theLeft
set j to theRight
set v to age of item ((theLeft + theRight) div 2) of theList
repeat while (j > i)
repeat while (age of item i of theList < v)
set i to i + 1
end repeat
repeat while (age of item j of theList > v)
set j to j - 1
end repeat
if (not i > j) then
tell theList to set {item i, item j} to {item j, item i}
set i to i + 1
set j to j - 1
end if
end repeat
if (theLeft < j) then quickSortL(theList, theLeft, j)
if (theRight > i) then quickSortL(theList, i, theRight)
end quickSortL