help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easy to add with push but not to the end of a list


From: Emanuel Berg
Subject: Re: Easy to add with push but not to the end of a list
Date: Tue, 29 Nov 2022 11:00:44 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Marcin Borkowski wrote:

> The difference is that you keep adding items at the front
> and then reverse the list /once/.

But if `nreverse' is O(1) then you can do it twice, first
nreverse, then `car', then nreverse.

Don't you have to flip all the cell cdr links? O(n)?

> Yet another option would be to keep the whole list in some
> variable, but use another variable (say, `last') as
> a "pointer" to the last cons

Yes of course :)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]