[Implemented] LinkedList: PushElement+PullElement

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

[Implemented] LinkedList: PushElement+PullElement

Post by Doobrey »

Dunno if anyone remembers these from AmiBlitz, but it makes working with large linked lists a lot quicker if you need to swap to another element and then back to the old one again.

Basically, just push the current element pointer on the stack, SelectElement() to another part of the list, get/set some info, then pull the old element pointer back again.

I know this can already be already be done with SelectElement(mylist(),old_index) , but doesn`t PB have to start from the first element and work up the list until the right element is found ?
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

You can use ChangeCurrentElement to instantly switch between elements you have a pointer to. The example in the manual should help.
Mat
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Post by Doobrey »

Doh, I really should RTFM more carefully.. :oops:
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I requested to Fred PushElement() and PopElement() for PB time ago (before PB forums exist, via email), just like Amiga BlitzBasic 2 commans: PushItem() and PopItem().
But in fact, MrMat gave the answer: it can be done with only a unique command in PB: ChangeCurrentElement().
Previously saving the current element pointer in a variable before change it. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Unless you implement some other stack on top of ChangeCurrentElement() then it's not quite the same as Push/PopItem. You had the ability to stack 8 (IIRC) items at the same time from the list.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

"Push" and "Pull" (or "Pop") are usually terms for managing stacks. We shouldn't start using them with linked lists.
Other verbs might better describe your intentions, whilst remaining technically correct when used with linked lists. What about simply using "Insert" and "Remove" ?
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post by okasvi »

better:

add&get
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

okasvi wrote:better:

add&get
I can live with that.
I don't see a big difference between 'insert' and 'add' either way, although 'add' surely is a bit more generic, which must be a good thing.
Your 'get' is definitely better, because my 'remove' seems to imply that the prior content is lost after 'removing' it. It's not, of course, it's merely transferrred to another variable, so that's why I like 'get' better. Thanks for your input...
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply