removing last element from the list

Raimo Niskanen raimo@REDACTED
Thu May 26 09:28:19 CEST 2005


The functionality from deque-1.0 has been incorporated in the
queue module since R9C, except that to keep the data structure
backwards compatible; the length data field had to be left out.
So e.g the queue:len() operation runs in O(N) instead of O(1). 
Maybe some other odd operations also are affected by this 
missing field.


serge@REDACTED (Serge Aleynikov) writes:

> You can either use the stdlib's queue module or look at the user's
> contribution of double ended queues:
> 
> http://erlang.org/user.html#deque-1.0
> 
> Serge
> 
> Gaspar Chilingarov wrote:
> > Hi all!
> > are there any really fast ways to remove last element from list?
> > list size is 5-15 elements, but it's not known at compile time.
> > I need to implement something like FIFO, new elements inserted in
> > list push old elements out.
> > now it looks line
> > NewList = [ Elem | lists:sublist(List, N-1)]
> > which probably is not the best way.
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list