Google Groups

sorting...


Bernhard Pfahringer Dec 15, 1998 12:00 AM
Posted in group: comp.lang.lisp
In article <31226719...@naggum.no>, Erik Naggum  <er...@naggum.no> wrote:
>
>  I do (sort (cons <element> <sorted-list>) <test>) when adding one element
>  at a time to a priority list.  profiling shows that it is irrelevant to
>  the execution time of the program, although I'd bet that some form of
>  programmer instinct would be triggered by this particular example and
>  would try to rewrite it.
>
Yep, why not use:

 (merge 'list (list <element>) <sorted-list> <test>)

Not much of a rewrite, O(n), might not bite as early for larger priority lists.

Bernhard
--
--------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for  http://www.ai.univie.ac.at/~bernhard/
Artificial Intelligence          bern...@ai.univie.ac.at