10-30-2004, 04:59 PM
Linked list example with pointers
Code:
defint a-z
'$include: 'user32.bi'
const MAXNODES = 10
const NULL = 0
type TNODE
id as short
prv as TNODE ptr
nxt as TNODE ptr
end type
type TLIST
head as TNODE ptr
tail as TNODE ptr
end type
dim list as TLIST
dim nodeTB(0 to MAXNODES-1) as TNODE
dim p as TNODE ptr
'' init list
list.head = varptr( nodeTB(0) )
list.tail = varptr( nodeTB(MAXNODES-1) )
p = NULL
for i = 0 to (MAXNODES-1)-1
nodeTB(i).id = i
nodeTB(i).prv = p
nodeTB(i).nxt = varptr( nodeTB(i+1) )
p = varptr( nodeTB(i) )
next i
nodeTB(MAXNODES-1).id = MAXNODES-1
nodeTB(MAXNODES-1).prv = p
nodeTB(MAXNODES-1).nxt = NULL
'' test it
dim res as string
p = list.head
do while( p <> NULL )
res = res + str$( p->id )
p = p->nxt
loop
MessageBox 0, res, "Result", MB_ICONASTERISK
oship me and i will give you lots of guurrls and beeea