HELP!
I'm trying to build a linked list. I'm trying to use objects for the cells in the list. I'm not a proficient object programmer. In the past, I've built such lists in 'C' using structures. This works very nicely. Now I'm trying to move everything into KBasic and am having difficulties because I don't fully understand what I'm doing!
My problem appears to be with referencing my current object. This is a bit of the code:
class ListHead
Dim ListLength as integer
Dim FirstCell as Node
Dim LastCell as Node
constructor ListHead
ListLength = 0
FirstCell = Null
LastCell = Null
end constructor
destructor ListHead
ListLength = 0
FirstCell = Null
LastCell = Null
end destructor
end class
class Node
Dim Info as Item
Dim NextNode as Node
constructor Node
Info = Null
NextNode = Null
end constructor
destructor Node
Info = Null
NextNode = Null
end destructor
Function DeleteNode(ListPtr as ListHead) as boolean
Dim NewPtr as Node = new Node
Dim ThisPtr as Node = new Node
ThisPtr = me
'Find preceding cell
NewPtr = ListPtr.FirstCell
Do While NewPtr <> NULL
if NewPtr.NextNode = ThisPtr then exit Do ' <<---------- this is the line I'm having problems with *****************!!!!!
NewPtr = NewPtr.NextNode
Loop
if NewPtr = NULL then return FALSE
NewPtr.Next = CellPtr.Next ' unlink cell
ListPtr.Length = ListPtr.Length - 1 'reduce the list length
if ListPtr.Length = 0 then ListPtr.Last = NULL
return TRUE
End Function
end class
My problem is that whatever I do to try to compare a cell pointer with the current instance of the object I get an 'incompatible types error' on this line of code. It was easy with 'C', you just compare pointers! With this though, I've tried just about everything I can think of (including various usages of 'Me') to compare the pointer reference held in NewPtr.NextNode with the current cell reference and nothing seems to work.
Please, one of you clever people out there, what am I doing wrong?