all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: LanX <lanx.perl@googlemail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Reverse pop, return value
Date: Tue, 17 Nov 2009 09:33:27 -0800 (PST)	[thread overview]
Message-ID: <cc7d6dbc-bf36-4ca5-954a-fd7c133f8765@o10g2000yqa.googlegroups.com> (raw)
In-Reply-To: 87hbstm6sp.fsf@lola.goethe.zz

Hi

On 17 Nov., 17:53, David Kastrup <d...@gnu.org> wrote:
> Reversing is O(n), popping from the front O(1), so working off the whole
> list is O(n).  Popping from the end is O(n), making work on the whole
> list O(n^2).

Thx David, good point!

I will keep it in mind for cases where I can't control that lists are
short.

Anyway my motivation was more to learn basic things like (prog1)!

Personally I prefer to delay optimizations (and potential complication
of the code) to the point when profiling shows the need for it.

But just from curiosity, having a FIFO stack situation (without
clearly separated IN/OUT-phases where I can just reverse once) , whats
the optimized way to push and pop then?

Maybe always keeping a pointer to the end of the list?

cheers
  Rolf


  reply	other threads:[~2009-11-17 17:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17 13:11 Remove last element in a list Nordlöw
2009-11-17 14:20 ` LanX
2009-11-17 15:32   ` Reverse pop, return value LanX
2009-11-17 15:48     ` Lennart Borgman
2009-11-17 16:53     ` David Kastrup
2009-11-17 17:33       ` LanX [this message]
     [not found]     ` <mailman.10897.1258472938.2239.help-gnu-emacs@gnu.org>
2009-11-17 17:20       ` LanX
2009-11-17 21:34         ` Barry Margolin
2009-11-18  0:28           ` LanX
2009-11-19 13:41             ` Barry Margolin
2009-11-17 21:26   ` Remove last element in a list Barry Margolin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc7d6dbc-bf36-4ca5-954a-fd7c133f8765@o10g2000yqa.googlegroups.com \
    --to=lanx.perl@googlemail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.