Buchempfehlung
Visual Basic 6 Kochbuch
Visual Basic 6 Kochbuch
Viele praktische Tipps zum Programmieren mit Visual Basic 6, die sich oft auch auf FB übertragen lassen. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Baumstruktur

Uploader:MitgliedPMedia
Datum/Zeit:13.12.2007 15:39:33

/' Baumstruktur
    written for: ProggerX
    written  by: PMedia
'/


Type Tree
    Usage:1 As UByte
    Value   As UInteger
    Leaf1   As Tree Ptr
    Leaf2   As Tree Ptr
End Type

Dim Layer         As UInteger
Dim SmplTree(511) As Tree
Dim In            As String
Dim Leaf          As UInteger
Dim I         As UInteger
Dim J         As UInteger
Dim K         As Tree Ptr

Do
    cls
    locate 1, 1
    Print "Layer:                " + Str(Layer)
    Print "Current leaf's ID:    " + Str(leaf)
    Print "Current leaf's value: " + Str(SmplTree(Leaf).Value)
    if (SmplTree(Leaf).Leaf1  = 0) then Print "Leaf 1's value:       NA"
    if (SmplTree(Leaf).Leaf1 <> 0) then Print "Leaf 1's value:       " + Str(SmplTree(Leaf).Leaf1->value)
    if (SmplTree(Leaf).Leaf2  = 0) then Print "Leaf 2's value:       NA"
    if (SmplTree(Leaf).Leaf2 <> 0) then Print "Leaf 2's value:       " + Str(SmplTree(Leaf).Leaf2->value)
    Print
    Print "Actions:"
    Print " u -> go up"
    Print " w -> set new value"
    if (SmplTree(Leaf).Leaf1  = 0) then Print " 1 -> create first leaf
    if (SmplTree(Leaf).Leaf1 <> 0) then Print "
1 -> goto first leaf"
    if (SmplTree(Leaf).Leaf2  = 0) then Print "
2 -> create second leaf
    if (SmplTree(Leaf).Leaf2 <> 0) then Print " 2 -> goto second leaf"
    Print " q -> quit"
    input ">", In

    Select Case In
    case "u"
        if (layer = 0) then
            Print "You're already at tree source!"
            Sleep 500
        Else
            K = @SmplTree(Leaf)
            J = -1
            For I = lbound(SmplTree) to ubound(SmplTree)
                If (SmplTree(i).Leaf1 = K) then
                    J = I
                End If
                If (SmplTree(i).Leaf2 = K) then
                    J = I
                End If
            Next
            If (J = -1) then
                Print "Fatal error: Parent not found!"
                Sleep 500
            else
                layer -= 1
                leaf = j
            end if
        End If
    case "w"
        input "Value>", i
        smpltree(leaf).value = i
    case "1"
        if (SmplTree(Leaf).Leaf1  = 0) then
            J = -1
            For I = lbound(SmplTree) to ubound(SmplTree)
                If (SmplTree(i).usage = 0) then
                    J = I
                End If
            Next
            If (I = -1) Then
                Print "Fatal error: tree size overflow!"
                Sleep 500
            else
                SmplTree(j).usage = 1
                SmplTree(Leaf).Leaf1 = @SmplTree(j)
                leaf = j
                layer += 1
            end if
        else
            K = SmplTree(Leaf).Leaf1
            J = -1
            For I = lbound(SmplTree) to ubound(SmplTree)
                If (@SmplTree(i) = K) then
                    J = I
                End If
            Next
            If (J = -1) then
                Print "Fatal error: Leaf not found!"
                Sleep 500
            else
                layer += 1
                leaf = j
            end if
        End If
    case "2"
        if (SmplTree(Leaf).Leaf2  = 0) then
            J = -1
            For I = lbound(SmplTree) to ubound(SmplTree)
                If (SmplTree(i).usage = 0) then
                    J = I
                End If
            Next
            If (I = -1) Then
                Print "Fatal error: tree size overflow!"
                Sleep 500
            else
                SmplTree(j).usage = 1
                SmplTree(Leaf).Leaf2 = @SmplTree(j)
                leaf = j
                layer += 1
            end if
        else
            K = SmplTree(Leaf).Leaf2
            J = -1
            For I = lbound(SmplTree) to ubound(SmplTree)
                If (@SmplTree(i) = K) then
                    J = I
                End If
            Next
            If (J = -1) then
                Print "Fatal error: Leaf not found!"
                Sleep 500
            else
                layer += 1
                leaf = j
            end if
        End If
    End Select

Loop Until lcase(In) = "q"