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

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

RE: [External] : Re: Easy to add with push but not to the end of a list


From: Drew Adams
Subject: RE: [External] : Re: Easy to add with push but not to the end of a list
Date: Mon, 28 Nov 2022 21:56:35 +0000

> Why is the below O(N), because of `last'?
> 
> (defun push-last (elem lst)
>   (let ((elem-lst (list elem)))
>     (if lst
>         (setcdr (last lst) elem-lst)
>       (setq lst elem-lst) )
>     lst) )

Yes.

(append lst (list elem)) also traverses the list
usually.



reply via email to

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