asp 동적 배열 은 Add,Insert,Remove,RemoveAt,Search 등 방법 을 제공 합 니 다.
Class Vector
Private vector_datas()
Private initial_capacity '
Private capacity_increment '
Private element_count '
Private max_capacity '
Private Sub Class_Initialize()
RemoveAll
End Sub
Public Function RemoveAll()
element_count = 0
initial_capacity = 10
capacity_increment = 10
max_capacity = initial_capacity
ReDim vector_datas(initial_capacity)
End Function
Public Property Get Count()
Count = element_count
End Property
Public Property Get Capacity()
Capacity = max_capacity
End Property
Public Property Get InitialCapacity()
InitialCapacity = initial_capacity
End Property
Public Property Get CapacityIncrement()
CapacityIncrement = capacity_increment
End Property
Public Default Property Get Item(index)
If IsObject(vector_datas(index)) Then
Set Item = vector_datas(index)
Else
Item = vector_datas(index)
End If
End Property
Public Function Add(element)
Call Insert(element_count, element)
End Function
Public Function Remove(element)
Dim index
index = Search(element)
RemoveAt(index)
Remove = index
End Function
Public Function RemoveAt(index)
Dim i
For i = index + 1 To element_count - 1 Step 1
Call InternalElement(i - 1, vector_datas(i))
Next
element_count = element_count - 1
If max_capacity - capacity_increment > element_count Then
max_capacity = max_capacity - capacity_increment
ReDim Preserve vector_datas(max_capacity)
End If
End Function
Public Function Search(element)
Dim i
For i = 0 To element_count - 1 Step 1
If vector_datas(i) = element Then
Search = i
Exit Function
End If
Next
Search = -1
End Function
Public Function Insert(index, element)
If index > element_count Then
Err.Raise 20903, "Vector", "Array Index Out Of Bounds.", "", 0
End If
If element_count = 0 Then
Call InternalElement(0, element)
ElseIf index = element_count Then
Call InternalElement(element_count, element)
Else
Dim i
For i = element_count To index + 1 Step -1
Call InternalElement(i, vector_datas(i - 1))
Next
Call InternalElement(index, element)
End If
element_count = element_count + 1
If element_count = max_capacity Then
max_capacity = element_count + capacity_increment
ReDim Preserve vector_datas(max_capacity)
End If
End Function
Public Function SetElementAt(index, element)
If index < 0 Or index > element_count - 1 Then
Err.Raise 20903, "Vector", "Array Index Out Of Bounds.", "", 0
End If
Call InternalElement(index, element)
End Function
Private Function InternalElement(index, element)
On Error Resume Next
If IsObject(element) Then
Set vector_datas(index) = element
Else
vector_datas(index) = element
End If
If Err.Number <> 0 Then
MsgBox("Vector InternalElement Error: " & vbCrLf & "Error Source: " & Err.Source & vbCrLf & "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf)
Err.Clear '
End If
End Function
Private Sub Class_Terminate() '
Erase vector_datas ' , ⒚ O Nothing
initial_capacity = Empty
capacity_increment = Empty
element_count = Empty
max_capacity = Empty
End Sub
End Class
CSDN , :http://blog.csdn.net/o1o2o3o4o5/archive/2009/10/20/4703033.aspx
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Shadows: Spooktober in Answer Set ProgrammingASP can be viewed as an extension of Prolog. Pure Prolog rules are based on definite clauses, that is Horn clauses which...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.