here is a so called my version/translation
i don't get it how CB can understand this crazy UDT
but oxygen complain here which is right that is not defined
Charles is there a way that o2 can process this:
error is in RED
WHILE list.node.nxt
plist = plist.node.nxt
WEND
''example of using a double linked list
'translation from Creative Baic by Aurel 27.12.2019.
'A node consists of two pointers
'one for the previous element
'and one for the next
TYPE node
nxt AS sys
prev AS sys
END TYPE
'our list has a node so we can
'create a linked list
TYPE list
node AS node
data AS string
number AS int
END TYPE
print "...UDT node & list created!"
Dim p,ref AS sys 'as pointer
'the function declarations.
! addtail (plist AS sys,data AS string,number AS int) As sys
! addhead (plist AS sys,data AS string,number AS int) As sys
! find (plist AS sys,data AS string)
! deleteall(plist AS sys)
print "...function declared!"
'main ///////////////////////////////////////////////
p = addtail(p,"entry0",12)
'/////////////////////////////////////////////////////
sub addtail(plist AS sys,data AS string,number AS int) as sys
'plist.node.nxt as list
if(plist = 0)
'if our list is empty just create
'a new one
plist = new(list)
else'
'find the last element
WHILE list.node.nxt
plist = plist.node.nxt
WEND
'create a new list variable
plist.node.nxt = new(list,1)
'point the new lists prev variable
'to the current last element
'this syntax uses multiple indirection
'both plist and nxt are pointers
plist.node.nxt.node.prev = plist
plist = plist.node.nxt
end if
plist.data = data
plist.number = number
return plist
end sub
'.................................................................
sub addhead(plist AS sys,data AS string,number AS int) as sys
if(plist = 0)
'if our list is empty just create a new one
plist = new(list,1)
else
'create a new list variable and put it first in line
plist.node.prev = new(list,1)
'make our new head point to the old head element
'this syntax uses multiple indirection
'both plist and prev are pointers
plist.node.prev.node.nxt = plist
plist = plist.node.prev
end if
plist.data = data
plist.number = number
return plist
end sub
'.................................................................
sub find(plist AS pointer,data AS string) as sys
Dim preturn AS sys
if(plist = 0)
preturn = 0
else
do
if plist.data = data
preturn = plist
else
plist = plist.node.nxt
endif
if preturn | (plist=0) then exit do
end do
end if
return preturn
end sub
'..................................................................
sub deleteall(plist AS sys)
Dim temp AS sys
'iterate through the list
'until the end
'deleting elements as we go.
while plist.node.nxt
temp = plist
plist = plist.node.nxt
delete temp
wend
delete plist
return
end sub