Structure blair
fil.l
*bin.blair
*hussein.bush
EndStructure
Structure bush
aznar.l
*ggg.blair
EndStructure
NewList saddam.blair()
NewList osama.bush()
AddElement(saddam())
AddElement(osama())
osama()\ggg=saddam()
osama()\ggg\fil=1234
;I can't do this:
ClearList(osama()\ggg);<-- doesn't work
;neither this:
AddElement(osama()\ggg);<-- doesn't work
;neither this:
*poi.blair=@saddam()
AddElement(*poi);<-- doesn't work
;and it would be interesting for these commands to admit pointers
;because sometimes programming is forced to implement unnecessary code, or more than one procedure
;where should be enought only one.
;If use pointers for these kind of commands (AddElement(),etc.) code would be sometimes smaller.
Debug saddam()\fil
Besides, i think that the ability of using pointers as parameters of such functions like CountList(), FirstElement(), ClearList(), etc. would make that LinkedList stuff was more coherent.
Since ResetList() and NextElement() don't accept normal pointers as argument, we are forced to implement 2 almost identical functions in this case, which could be 3 or more functions almost identical in other cases; look:
That would be nice to have the list functions accept pointers... could get REALLY tedious if you were keeping many lists and needed many functions for doing the same thing with all of them... PolyVector to the rescue!
lol...how sad is this that i've only posted twice now and they've both been on linked lists...anywho...if you need a quick-fix here you go:
Nice code PolyVector but doing it like that means you would need many List structures to handle all data types. I was thinking about having a more generic and neat solution
Brr, sorry this can't accept inserting Code when i write the message.
Well i hope you understand it.
I take advantage to add that your method, if in a big program with lots of structures, and lots of functions, we forced to use linked lists in an own way (out of PureBasic commands and functions offer us), and to add to all (or most) of structures 2 more elements inside: *Next.structure and *Previous.structure.
Yeah, I do agree that the linked list commands need a little work... Maybe I'm wierd but I always use linked lists the way I described above only because it makes more sense to me... hehe I guess we all code differently...
You said:
"I always use linked lists the way I described above only because it makes more sense to me... "
However, keep in mind that the main matter of Linked Lists as is implemented in PB, is that each element in list points internally (made by PB transparent to the programmer) to its next and to its previous element, so i understand that it has more sense to you to program like that, but the matter is to make it easy and transparent to the programmer.
So your programs are efficient, but it is redundant to have to use externally a pointer to next and another to previous element in each element in list.