How can I use a linked list as a parameter for a function?

Just starting out? Need help? Post your questions and find answers here.
Dennis
New User
New User
Posts: 2
Joined: Tue Aug 05, 2003 3:25 pm

How can I use a linked list as a parameter for a function?

Post by Dennis »

Hello Everybody,

I have the problem, that I can not use a linked list as a parameter for a function?
What is the correct syntax/declaration for such a function??

Thx
Dennis
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

all linkedlists are declared in global.
so you can access them inside procedures.

something like that :

Code: Select all

NewList test.s()

Procedure AddItem()
  
  AddElement( test() )
  test() = "new item"
  
EndProcedure

AddItem()
Debug test()
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
venom
User
User
Posts: 56
Joined: Fri Jul 25, 2003 1:54 pm
Location: Australia

Post by venom »

AddElement returns a pointer to the linkedlist with containing the next and previous pointers.

Code: Select all

Structure something
  a.l
EndStructure

NewList abc.something()

AddElement(abc())  ; returns ptr to list of something
abc()  ; returns a ptr to something (I believe its offset of the ptr above)
Dennis
New User
New User
Posts: 2
Joined: Tue Aug 05, 2003 3:25 pm

Post by Dennis »

my idea was something like that:

Structure something
a.l
EndStructure

function add (localist.something())
addElement(locallist())
endFunction

newList myList.something

add(myList())


This way did not work!
venom
User
User
Posts: 56
Joined: Fri Jul 25, 2003 1:54 pm
Location: Australia

Post by venom »

I think you can only read the data from the ptrs, not treat them like a true PureBasic linkedlist.
Post Reply