⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctree.cls

📁 Visual Basic 6 大学教程的代码
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CTree"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Fig. 21.15
' Class CTree
Option Explicit
Private mRoot As CTreeNode
Private mOutputString As String

' Insert a new node in the binary search tree.
' If the root node is null, create the root node here.
' Otherwise, call the insert procedure of class TreeNode.
Public Sub InsertNode(value As Variant)
   If mRoot Is Nothing Then
      Set mRoot = New CTreeNode
      mRoot.Data = value
   Else
      mRoot.Insert (value)
   End If
End Sub
   
' Preorder Traversal
Public Sub PreorderTraversal()
   mOutputString = ""
   Call PreorderHelper(mRoot)
End Sub

' Recursive procedure to perform preorder traversal
Private Sub PreorderHelper(node As CTreeNode)
   If node Is Nothing Then
      Exit Sub
   End If
   
   mOutputString = mOutputString & node.Data & " "
   Call PreorderHelper(node.Left)
   Call PreorderHelper(node.Right)
End Sub
   
' Inorder Traversal
Public Sub InorderTraversal()
   mOutputString = ""
   Call InorderHelper(mRoot)
End Sub

' Recursive procedure to perform inorder traversal
Private Sub InorderHelper(node As CTreeNode)
   If node Is Nothing Then
      Exit Sub
   End If
   
   Call InorderHelper(node.Left)
   mOutputString = mOutputString & node.Data & " "
   Call InorderHelper(node.Right)
End Sub

' Postorder Traversal
Public Sub PostorderTraversal()
   mOutputString = ""
   Call PostorderHelper(mRoot)
End Sub

' Recursive procedure to perform Postorder traversal
Private Sub PostorderHelper(node As CTreeNode)
   If node Is Nothing Then
      Exit Sub
   End If
   
   Call PostorderHelper(node.Left)
   Call PostorderHelper(node.Right)
   mOutputString = mOutputString & node.Data & " "
End Sub

Public Property Get Output() As Variant
   Output = mOutputString
End Property

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -