Re: Sorting of two interdependent sequences
- Posted by DerekParnell (admin) Aug 21, 2012
- 1094 views
SnakeCharmer said...
There are two sequences, first for names and second for numbers. I need to sort numbers, but names should be sorted as appropriate.
include std/sort.e sequence Names = {"Army of Lovers", "Boney M.", "C. C. Catch", "Dschinghis Khan"} sequence Numbers = {1987, 1975, 1985, 1979} function sorter(sequence A, sequence B) sequence x x = repeat({0,0}, length(A)) for i = 1 to length(x) do x[i][1] = A[i] x[i][2] = B[i] end for x = sort(x) for i = 1 to length(x) do A[i] = x[i][1] B[i] = x[i][2] end for return {A,B} end function sequence t t = sorter(Numbers, Names) t = sorter(Names, Numbers)