Re: [GEN] custom_sort by ELEMENT of sequence?
- Posted by Graeme <graemeburke at CROSSWINDS.NET> Jan 14, 2001
- 461 views
At 03:22 AM 13/01/01 -0800, you wrote: >Graeme, > >Jeeze, <slapping head>, > >I guess I've tried so hard to impress upon myself that passing values to a >function by parameter is "cleaner" than by using global variables, I totally >forgot about doing it with an "external" variable! Thanks Graeme, and >thanks also for using an *example* to explain it; even though I can >understand it in the abstract, the example does help. > >But I'm still wondering if I am correct in thinking that because routine_id >is used, one *can't* pass the element number to the sort function by >parameter, and that there is *some*(?) reason that it has to be done via >routine_id? > >Dan Oakey-Doaky, global function sort_by_element(integer element, sequence x) --99% Sort.e RDS integer gap, j, first, last object tempi, tempj last = length(x) gap = floor(last / 3) + 1 while 1 do first = gap + 1 for i = first to last do tempi = x[i] j = i - gap while 1 do tempj = x[j] if compare(tempi[element],tempj[element]) >= 0 then j += gap exit end if x[j+gap] = tempj if j <= gap then exit end if j -= gap end while x[j] = tempi end for if gap = 1 then return x else gap = floor(gap / 3) + 1 end if end while end function ----------------------------------------------------