Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
freeBASIC (a 32-bit QB-syntax compatible compiler) preview..
#42
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
Reply


Messages In This Thread
Excelent work! - by Ravyne - 10-28-2004, 11:43 AM
freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - by Blitz - 10-30-2004, 04:59 PM
First impression... - by ToohTooh - 11-01-2004, 03:30 PM
Random naive questions - by dilettante - 11-14-2004, 10:39 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)