Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: is there really no efficient way to delete an element from a list??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24044] Re: [mg23925] is there really no efficient way to delete an element from a list??
  • From: Leszek Sczaniecki <lsczan at home.com>
  • Date: Wed, 21 Jun 2000 02:20:04 -0400 (EDT)
  • References: <oCd35.115$x6.34207@ralph.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

David Withoff wrote:

> Use linked lists, as in
>
> queue={1,{2,{3,{4}}}}
> queue = Rest[queue]

You probably meant
    queue = First[Rest[queue]]

I can clearly see how (with some small improvements) one can define stack this way

    stack={1,{2,{3,{4}}}}
    Pop[stack_] := First[Rest[stack]]
    Push[x_, stack_] := {x, stack}

However, if you define Dequeue as
    Dequeue[queue_] := First[Rest[queue]]
I am curious  how you define Enqueue?

-- Leszek Sczaniecki

>
>
> Dave Withoff
> Wolfram Research
>
> > hi, i tried to implement a queue with mathematica;
> > is it possible that there is no O(1) way to get
> > queue = Rest[queue]  ??
> >
> > it seems that mathematica uses call by value instead of call by reference
> > here;
> > i know that there are PrependTo[] and ApendTo[] for building the list; is
> > there any equivalent to these functions to remove elements?
> >
> > or is there another way to implement a stack or queue with constant time
> > access?
> >
> > --martin.
> >
> > ----------------------------------------------------------------------------
> > Martin Bauer                          email:  martin.bauer at in.tum.de
> > Department of Computer Science          www:  http://www.in.tum.de/~bauerma
> > Technische Universitat Munchen          tel:  +49-89-289-25724
> > D-80290 Munchen, Germany               room:  3202  main bldg, Arcisstr.21
> > ----------------------------------------------------------------------------



  • Prev by Date: Re: how much graphics RAM?
  • Next by Date: Re: how much graphics RAM?
  • Previous by thread: Re: is there really no efficient way to delete an element from a list??
  • Next by thread: bug in JacobiAmplitude numerics?