Efficient list rotation

Luke Gorrie luke@REDACTED
Fri Apr 15 11:12:48 CEST 2005

Hi Joel,

The problem is to move the first element of the list to the end?
Here's a simple way:

  move_first_to_last([H|T]) -> T++[H].

The list would be representing a queue. There is also a queue data
structure in OTP ('queue' module) which is quite a cute, I remember
stepping through the algorithm with billiard balls when I was learning
Erlang :-). For your purposes a plain ol' list sounds fine.

Or do you really need to move the Nth element to the tail instead?

More information about the erlang-questions mailing list