General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old March 23rd, 2008, 10:08 AM
pauljones7575 pauljones7575 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: UK
Posts: 1 pauljones7575 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 47 sec
Reputation Power: 0
Facebook
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Binary Tree


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway