Re: is there really no efficient way to delete an element from a list??
- To: mathgroup at smc.vnet.net
- Subject: [mg23983] Re: [mg23925] is there really no efficient way to delete an element from a list??
- From: BobHanlon at aol.com
- Date: Sun, 18 Jun 2000 03:01:05 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 6/16/2000 1:22:20 AM, b at hcii.de writes: >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? $Version "4.0 for Power Macintosh (April 20, 1999)" queue = Range[5]; Do[Print[queue]; queue = Rest[queue], {5}] {1, 2, 3, 4, 5} {2, 3, 4, 5} {3, 4, 5} {4, 5} {5} queue = Range[5]; Do[Print[queue]; queue = Drop[queue, 1], {5}] {1, 2, 3, 4, 5} {2, 3, 4, 5} {3, 4, 5} {4, 5} {5} queue = Range[5]; Do[Print[queue]; queue = Drop[queue, -1], {5}] {1, 2, 3, 4, 5} {1, 2, 3, 4} {1, 2, 3} {1, 2} {1} Bob Hanlon