|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Binary Tree
Hi, I wander if anyone can help me with this enquiry. I am not looking for anyone to provide me with the answer as I am a student and want to resolvemost of this myself but would appreciate it if someone could point in the direction of where I am going wrong her.
I have an assignment to store details of car registration details and cost in a binary tree. I am using visual basic and have created public type to contain the registration, cost and also a left and right pointer to show how each peice of data links together in the binary tree. My problem is sthat I can add a car registration and cost to the array but I can't assign the required left or right pointer to the data in the array. I have copied the code I have so far below and any advice would be greatefully appreciated. Option Explicit Private Type CarReg Reg As String * 7 Cost As Single LP As Integer RP As Integer End Type Dim r(0 To 20) As CarReg Dim counter As Integer Dim root As Integer Dim i As Integer Private Sub cmdAdd_Click() 'check number of characters If txtCarReg.Text = "" Or Len(txtCarReg.Text) > 7 Then MsgBox "Please enter a valid registration" End If 'check if this is the first piece of data If counter = 0 Then r(counter).Reg = txtCarReg.Text r(counter).Cost = Val(txtCarCost.Text) root = counter counter = counter + 1 Else 'find another space r(counter).Reg = txtCarReg.Text r(counter).Cost = Val(txtCarCost.Text) counter = counter + 1 If r(counter).Reg > r(root).Reg And r(root).RP = -1 Then For counter = 1 To 20 If r(counter).Reg = "qqqqqqq" Then ' we found a space r(0).RP = counter r(counter).Reg = txtCarReg.Text r(counter).Cost = Val(txtCarCost.Text) counter = 21 Else MsgBox "The tree is full!!!" End If Next counter End If If r(counter).Reg > r(root).Reg And r(root).LP = -1 Then For counter = 1 To 20 If r(counter).Reg = "qqqqqqq" Then ' we found a space r(0).LP = counter r(counter).Reg = txtCarReg.Text r(counter).Cost = Val(txtCarCost.Text) counter = 21 Else MsgBox "The tree is full!!!" End If Next counter End If End If Call printit End Sub Private Sub Form_Load() For i = 0 To 20 r(i).Reg = "QQQQQQQ" r(i).LP = -1 r(i).RP = -1 Next i root = -1 counter = 0 Call printit End Sub Private Sub printit() Cls Print "No. Reg Cost LP RP" For i = 0 To 20 Print i; Tab; r(i).Reg; Tab; r(i).Cost; Tab; r(i).LP; Tab; r(i).RP Next i Print "" Print "Root: " & root Print "Count: " & counter End Sub |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Binary Tree |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|