Created
June 15, 2016 14:21
-
-
Save kevindb/5ae3724c7a724b50bd4b3b404cbcd263 to your computer and use it in GitHub Desktop.
Basic recursive sort in ColdFusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public array function sort ( | |
required array arr, | |
numeric pos = 1 | |
) { | |
local.nextPos = arguments.pos + 1; | |
if (arguments.arr[arguments.pos] > arguments.arr[local.nextPos]) { | |
local.tempLeft = arguments.arr[arguments.pos]; | |
arguments.arr[arguments.pos] = arguments.arr[local.nextPos]; | |
arguments.arr[local.nextPos] = local.tempLeft; | |
if (arguments.pos > 1) { | |
local.prevPos = arguments.pos-1; | |
} else { | |
local.prevPos = 1; | |
} | |
arguments.arr = sort(arr=arguments.arr, pos=local.prevPos); | |
} else if (local.nextPos < arrayLen(arguments.arr)) { | |
arguments.arr = sort(arr=arguments.arr, pos=local.nextPos); | |
} | |
return arguments.arr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment