国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp 動(dòng)態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。

2020-07-27 12:53:14
字體:
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:

Class Vector

Private vector_datas()
Private initial_capacity '初始化容量
Private capacity_increment '容量增量
Private element_count '元素?cái)?shù)
Private max_capacity '總?cè)萘?

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 '清除錯(cuò)誤信息
End If
End Function

Private Sub Class_Terminate() '類銷毀
Erase vector_datas '釋放數(shù)組占用的內(nèi)存, 主站蜘蛛池模板: 济南市| 六盘水市| 雷山县| 乐业县| 达州市| 林西县| 濮阳县| 镇雄县| 翼城县| 堆龙德庆县| 金山区| 和平县| 永城市| 巴东县| 梅州市| 屏南县| 景宁| 罗田县| 辛集市| 枝江市| 九寨沟县| 汶上县| 榕江县| 昭觉县| 石柱| 韩城市| 阿坝县| 高阳县| 五大连池市| 尖扎县| 盘锦市| 林口县| 西青区| 防城港市| 绥中县| 土默特右旗| 南城县| 浏阳市| 乌海市| 临清市| 绥阳县|