Re: modified reverse

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi rforno,

> Rob:
> The following modified reverse routine is simpler and, most of the times,
> slightly faster than the standard one. However, I noticed that the
> comparison between the two is affected by the type of data (integer or
not,
> simple or compound sequence), and even it seems that the way of
generating
> the data (by means of a single sentence or by a loop) affects the
resulting
> timings. Any explanation for such a behavior?
> 
> global function reverse1(sequence s)
>     integer n
>     sequence t
>     n = length(s)
>     t = repeat(0,n)
>     for i = 1 to n do
>         t[n] = s[i]
>         n -= 1
>     end for
>     return t
> end function

rforno, Rob,
the *very* interesting solution,
but how about the second one,
just inspired by rforno's the first:

sequence S
S={{1},{2},{3},{4},{5},{6},{7},{8},{9}}

global function reverse2(sequence s)
 integer n
   sequence t
    t = s
    n = length(s)
    for i = 1 to n do
     t[n] = s[i]
       n -= 1
    end for
   return t
end function

? reverse2(S)   ----     smile

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu