参考某人的js二叉树写的asp的二叉树,有问题欢迎提出
Class TreeSort
Private LeftNode
Private MiddleNode
Private RightNode
Private Sub Class_Initialize()
Set LeftNode = Nothing
Set RightNode = Nothing
MiddleNode = Null
End Sub
Private Sub Class_Terminate()
Set LeftNode = Nothing
Set RightNode = Nothing
MiddleNode = Null
End Sub
Public Sub Add(ByVal Value)
If IsNull(Node) Then
Node = Value
Exit Sub
End If
Dim NewNode
Set NewNode = New TreeSort
NewNode.Node = Value
If Node >= Value Then
If Left Is Nothing Then
Set Left = NewNode
Else
Left.Add(Value)
End If
Else
If Right Is Nothing Then
Set Right = NewNode
Else
Right.Add(Value)
End If
End If
Set NewNode = Nothing
End Sub
Public Function Print()
If Not(Left Is Nothing) Then
Left.Print()
End If
PrintArray(Node)
If Not(Right Is Nothing) Then
Right.Print()
End If
End Function
Public Property Set Left(ByVal Object)
Set LeftNode = Object
End Property
Public Property Get Left()
Set Left = LeftNode
End Property
Public Property Let Node(ByVal Value)
MiddleNode = Value
End Property
Public Property Get Node()
Node = MiddleNode
End Property
Public Property Set Right(ByVal Object)
Set RightNode = Object
End Property
Public Property Get Right()
Set Right = RightNode
End Property
End Class
Dim newArrArray
newArrArray=Array()
Sub PrintArray(ByVal newValue)
Dim arrNewArray(),i
ReDim arrNewArray(UBound(newArrArray)+1)
For i=0 To UBound(newArrArray)
arrNewArray(i) = newArrArray(i)
Next
arrNewArray(i) = newValue
newArrArray = arrNewArray
End Sub
Function TSort(ByVal arrSortArray)
Dim TCLS,i
Set TCLS = New TreeSort
For i = 0 To UBound(arrSortArray)
TCLS.Add(arrSortArray(i))
Next
TCLS.Print()
TSort = newArrArray
End Function
arr=Array(1,2,5,3,2,6,3,2)
arr=TSort(arr)
Document.Write(Join(arr,","))