ligh
Newish
Posts: 2
|
Post by ligh on Nov 12, 2003 18:49:20 GMT -5
struc IntNode dim value dim IntNode &next endstruc
|
|
|
Post by Tom Mulgrew on Nov 12, 2003 20:39:23 GMT -5
If you rename "&next" to "&nextNode" or something it will work fine. ("next" is a reserved word.) struc IntNode dim value dim IntNode &nextNode endstruc
' Setup (backward) linked list dim IntNode nodes(10), i for i = 1 to 10: nodes (i).value = i: &nodes (i).nextNode = &nodes(i-1): next
' Iterate it dim IntNode &node &node = &nodes (10) for i = 0 to 10 printr node.value &node = &node.nextNode next
Although I just realised that there is no way to check if a pointer is set or not, so can't detect when you've reached the end of the chain.. I'll add a function in the next release (which should be this weekend). -Tom struc IntNode dim value dim IntNode &next endstruc
|
|
|
Post by Tom Mulgrew on Nov 13, 2003 21:35:29 GMT -5
I've added "null" to the language. It can be assigned to any pointer or compared with a pointer for equality or inequality.
For example:
struc IntNode dim value dim IntNode &nextNode endstruc
' Setup (backward) linked list dim IntNode nodes(10), i for i = 1 to 10: nodes (i).value = i: &nodes (i).nextNode = &nodes(i-1): next
' Iterate it dim IntNode &node &node = &nodes (10) while not &node = null printr node.value &node = &node.nextNode wend
(You'll have to wait for the next release to try it out though.)
|
|