VB也用指针!!!

Dynamic 2002-01-23 11:13:38
我用vb做了一个二叉树排序的代码,(经典),
想要源代码的留下email:
我的email:cowknife@163.com
...全文
217 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dynamic 2002-01-25
  • 打赏
  • 举报
回复
?????
Dynamic 2002-01-25
  • 打赏
  • 举报
回复
?
Dynamic 2002-01-25
  • 打赏
  • 举报
回复
'类Tree
Private l As Tree
Private r As Tree
Private v As Variant

Public Property Get LeftLink() As Tree
Set LeftLink = l
End Property

Public Property Set LeftLink(NewValue As Tree)
Set l = NewValue
End Property

Public Property Get RightLink() As Tree
Set RightLink = r
End Property

Public Property Set RightLink(NewValue As Tree)
Set r = NewValue
End Property

Public Property Get Value() As Variant
Value = v
End Property

Public Property Let Value(NewValue As Variant)
v = NewValue
End Property


'测试代码
Dim Root As Tree

Private Sub Command1_Click()
Dim a
a = Array(30, 12, 23, 42, 13, 32, 22, 53, 25)
Dim i As Long
If Root Is Nothing Then Set Root = New Tree
For i = 0 To UBound(a)
Ins Root, a(i)
Next
Disp Root
Remove Root
End Sub

Sub Ins(t As Tree, v As Variant)
Dim s As Tree
If IsEmpty(t.Value) Then
t.Value = v
ElseIf v < t.Value Then
If t.LeftLink Is Nothing Then Set t.LeftLink = New Tree
Ins t.LeftLink, v
Else
If t.RightLink Is Nothing Then Set t.RightLink = New Tree
Ins t.RightLink, v
End If
End Sub

Sub Disp(t As Tree)
If t Is Nothing Then
Else
Disp t.LeftLink
Debug.Print t.Value
Disp t.RightLink
End If
End Sub

Sub Remove(t As Tree)
If Not t.LeftLink Is Nothing Then Remove t.LeftLink
If Not t.RightLink Is Nothing Then Remove t.RightLink
If Not t Is Nothing Then Set t = Nothing
End Sub
'QQ:24821781
'还有更经典的,有兴趣请发EMAIL至:cowknife@163.com
vicro 2002-01-25
  • 打赏
  • 举报
回复
关注:
我的Email:thirght@yesky.com
Dynamic 2002-01-25
  • 打赏
  • 举报
回复
'类TREE
Private l As Tree
Private r As Tree
Private v As Variant

Public Property Get LeftLink() As Tree
Set LeftLink = l
End Property

Public Property Set LeftLink(NewValue As Tree)
Set l = NewValue
End Property

Public Property Get RightLink() As Tree
Set RightLink = r
End Property

Public Property Set RightLink(NewValue As Tree)
Set r = NewValue
End Property

Public Property Get Value() As Variant
Value = v
End Property

Public Property Let Value(NewValue As Variant)
v = NewValue
End Property
Dynamic 2002-01-25
  • 打赏
  • 举报
回复
不用那么累,看我的代码,这是一个类模块,类名TREE
Private l As Tree
Private r As Tree
Private v As Variant

Public Property Get LeftLink() As Tree
Set LeftLink = l
End Property

Public Property Set LeftLink(NewValue As Tree)
Set l = NewValue
End Property

Public Property Get RightLink() As Tree
Set RightLink = r
End Property

Public Property Set RightLink(NewValue As Tree)
Set r = NewValue
End Property

Public Property Get Value() As Variant
Value = v
End Property

Public Property Let Value(NewValue As Variant)
v = NewValue
End Property

这是测试代码:
Dim Root As Tree
Private Sub Command1_Click()
Dim a
a = Array(30, 12, 23, 42, 13, 32, 22, 53, 25)
Dim i As Long
If Root Is Nothing Then Set Root = New Tree
For i = 0 To UBound(a)
Ins Root, a(i)
Next
Disp Root
Remove Root
End Sub

Sub Ins(t As Tree, v As Variant)
Dim s As Tree
If IsEmpty(t.Value) Then
t.Value = v
ElseIf v < t.Value Then
If t.LeftLink Is Nothing Then Set t.LeftLink = New Tree
Ins t.LeftLink, v
Else
If t.RightLink Is Nothing Then Set t.RightLink = New Tree
Ins t.RightLink, v
End If
End Sub

Sub Disp(t As Tree)
If t Is Nothing Then
Else
Disp t.LeftLink
Text1.Text = t.Value
Disp t.RightLink
End If
End Sub

Sub Remove(t As Tree)
If Not t.LeftLink Is Nothing Then Remove t.LeftLink
If Not t.RightLink Is Nothing Then Remove t.RightLink
If Not t Is Nothing Then Set t = Nothing
End Sub

leefc 2002-01-25
  • 打赏
  • 举报
回复
leefc@163.com
zyl910 2002-01-25
  • 打赏
  • 举报
回复
To shawls(小山(坚持VB,学Delphi和C#)):
有CopyMoney函数吗?
如果有的话,那也有CopyFen(复制分)。
zyl910 2002-01-25
  • 打赏
  • 举报
回复
哇!这么多人!
那我也要!zyl910@sina.com
whose 2002-01-25
  • 打赏
  • 举报
回复
feiyingaction@sohu.com
shawls 2002-01-25
  • 打赏
  • 举报
回复

用copymoney不是很累?用valstr 把!


btw:好像是这个函数!

apple_boy 2002-01-25
  • 打赏
  • 举报
回复
多谢:apple_sir@x263.net
ccto 2002-01-25
  • 打赏
  • 举报
回复
我也想要:ccto@x263.net
lzj_freedom 2002-01-25
  • 打赏
  • 举报
回复
lzj_freedom@sohu.com
感激不尽
lht999 2002-01-25
  • 打赏
  • 举报
回复
lht999a@sina.com
leaf_xuan_xuan 2002-01-25
  • 打赏
  • 举报
回复
leaf_1979@sina.com
thx
yangzhaoyu 2002-01-25
  • 打赏
  • 举报
回复
zhaoyu_yang@hotmail.com
lichard 2002-01-25
  • 打赏
  • 举报
回复
legeal@163.net
chsl918 2002-01-25
  • 打赏
  • 举报
回复
PLS mail to Me :chsl@cattsoft.com
wjhwdm 2002-01-25
  • 打赏
  • 举报
回复
我也想要:wjhwdm@163.com
加载更多回复(8)

741

社区成员

发帖
与我相关
我的任务
社区描述
VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧