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 > > ----------------------------------------------------------------------------