<cffunction name="mergeSort" hint="Sorts arrays of structs">
<cfargument name="arr" type="Array" required="yes">
<cfif Arraylen(arr) LTE 1>
<cfreturn arr />
</cfif>
<cfset left_ = ArrayNew(1)>
<cfset right_ = ArrayNew(1)>
<cfset mid_ = Int(Arraylen(arr) / 2)>
<cfloop index="i" from="1" to="#mid_#">
<cfset arrayAppend(left_, arr[i])>
</cfloop>
<cfloop index="j" from="#mid_+1#" to="#ArrayLen(arr)#">
<cfset arrayAppend(right_, arr[j])>
</cfloop>
<cfreturn merge( mergeSort(left_), mergeSort(right_) )>
</cffunction>
<cffunction name="merge" hint="Merges two arrays">
<cfargument name="left_" required="yes" type="Array">
<cfargument name="right_" required="yes" type="Array">
<cfset result = ArrayNew(1)>
<cfloop condition="ArrayLen(left_) GT 0 AND ArrayLen(right_) GT 0">
<cfif left_[1].attr3 LTE right_[1].attr3>
<cfset arrayAppend(result, left_[1])>
<cfset arrayDeleteAt(left_, 1)>
<cfelse>
<cfset arrayAppend(result, right_[1])>
<cfset arrayDeleteAt(right_, 1)>
</cfif>
</cfloop>
<cfif ArrayLen(left_) GT 0>
<cfloop array="#left_#" index="v">
<cfset ArrayAppend(result, v)>
</cfloop>
</cfif>
<cfif ArrayLen(right_) GT 0>
<cfloop array="#right_#" index="v">
<cfset ArrayAppend(result, v)>
</cfloop>
</cfif>
<cfreturn result />
</cffunction>
它在名为“attr3”的结构键上对结构数组进行排序。结果是,它似乎正确地拆分了列表,但随后继续将相同的列表附加到结果集。因此,例如,如果我将左\u3.attr3作为“Title”,右\u3.attr3作为“Another”,结果就是“Title”、“Another”、“Another”。。等。