My first program: sublime (reverse of "extract" function)
- Posted by SocIoDim May 17, 2013
- 2567 views
I needed to sort the list to perform certain operations on the elements, and then restore them in the order in which they were before sorting.
function sublime(sequence Unsorted, sequence Sorted) sequence Sublime = {} integer Index for i = 1 to length(Sorted) do Index = 0 loop do Index = find(Sorted[i], Unsorted, Index+1) until find(Index, Sublime) = 0 end loop Sublime &= Index end for return Sublime end function Unsorted = {0.5, 0.2, 0.4, 0.3, 0.1, 0.5} Sorted = sort(Unsorted) if equal(extract(Sorted, sublime(Unsorted, Sorted)), Unsorted) then puts(1, "sublime test passed!\n") end if
It is not optimal and potentially get hung up, but enough for me.