Computer Science Canada

automatic recursive tree sort problems

Author:  Ambiguities [ Wed Mar 11, 2009 6:24 pm ]
Post subject:  automatic recursive tree sort problems

I'm trying to create a tree in memory using recursion but i don't think i have it right. variables are entered in a loop and they are sent to this procedure


code:

procedure addtotree (var locptr, crp : ^student)

    if root = nil then
        root := crp
    end if
    if crp -> lname > locptr -> lname then
        if locptr -> gtp not= nil then
            addtotree (locptr -> gtp, crp)
        else
            locptr -> gtp := crp
        end if
    elsif crp -> lname < locptr -> lname then
        if locptr -> ltp not= nil then
            addtotree (locptr -> ltp, crp)
        else
            locptr -> ltp := crp
        end if
    end if
end addtotree


i don't know why it isn't working or if it is why it isn't allowing itself to be read with this :/



code:

procedure show (crp : ^student, x : int)

    if crp -> ltp not= nil then
        showtreefull (crp -> ltp, x)
    end if

    put crp -> name

    if crp -> gtp not= nil then
        showtreefull (crp -> gtp, x)
    end if
end show

Author:  Tony [ Wed Mar 11, 2009 6:28 pm ]
Post subject:  RE:automatic recursive tree sort problems

be more specific about the errors. In which way is it not working? How does it prevent itself from be read?

Author:  Ambiguities [ Wed Mar 11, 2009 8:31 pm ]
Post subject:  Re: automatic recursive tree sort problems

i hate to sound dumb because this is probably pretty obvious to more experienced people but i have no idea how to solve this problem... i know if i stare at it long enough i will be able to figure out the logical fault... all i know is whenever i try to read the tree it only gives me the first input wich has been set as root. it won't display anything else... any help would be appreciated :)

Author:  Tony [ Wed Mar 11, 2009 8:38 pm ]
Post subject:  RE:automatic recursive tree sort problems

it likely means that both
code:

crp -> ltp not= nil

and
code:

crp -> gtp not= nil

evaluate to false

Author:  Ambiguities [ Wed Mar 11, 2009 8:53 pm ]
Post subject:  Re: automatic recursive tree sort problems

thankyou for the help:)


: