Page 1 of 1
[Implemented] LinkedList: PushElement+PullElement
Posted: Mon May 09, 2005 10:36 pm
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 ?
Posted: Mon May 09, 2005 11:05 pm
by MrMat
You can use ChangeCurrentElement to instantly switch between elements you have a pointer to. The example in the manual should help.
Posted: Mon May 09, 2005 11:09 pm
by Doobrey
Doh, I really should RTFM more carefully..

Posted: Tue May 10, 2005 9:25 am
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.

Posted: Tue May 10, 2005 11:03 am
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.
Posted: Tue May 10, 2005 1:03 pm
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" ?
Posted: Tue May 10, 2005 10:23 pm
by okasvi
better:
add&get
Posted: Wed May 11, 2005 12:43 am
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...