陣列搞花樣

在God 函式之後,出現了以Array 為軸心的陣列處理函式ResDim 以及ResPush。即使一開始的ResDim 掛著一身bug,但是在ArrayType 出現之後,目前是可以安心使用的函式。

 

從這之後,陣列處理的函式就常常被掛上Res 的字首。ResSteal 用來刪除陣列中某一個索引,這在不定型巢狀迴圈中幾乎都會用到。

]Function ResSteal(ByVal Origin As Array, ByVal Index As Integer) As Array

]If (Origin Is Nothing) Then

]Return Nothing

]End If

]Dim Result as Array = Array.CreateInstance(ArrayType(Origin), (UBound(Origin) - LBound(Origin) + 1) - 1)

]For i1 As Integer = LBound(Origin) To (Index - 1) Step 1

]Result(i1) = Origin(i1)

]Next

]For i1 As Integer = Index + 1 To UBound(Origin) Step 1

]Result(i1 - 1) = Origin(i1)

]Next

]Return Result

]End Function

 

ResHang 用來把一個陣列掛到另一個陣列上。

]Function ResHang(ByVal Origin As Array, ByVal Addition As Array, Optional ByVal Index As Integer = -1) As Array

]If (Origin Is Nothing) Then

]Return Addition

]End If

]If (Addition Is Nothing) Then

]Return Nothing

]End If

]If (Index = -1) Then

]Index = UBound(Origin) + 1

]End If

]Index = Castle(Index, LBound(Origin), UBound(Origin) + 1)

]Dim Result As Array = Nothing

]For i1 As Integer = LBound(Origin) To Index - 1 Step 1

]Result = ResPush(Result, Origin(i1))

]Next

]For i1 As Integer = LBound(Addition) To UBound(Addition) Step 1

]Result = ResPush(Result, Addition(i1))

]Next

]For i1 As Integer = Index To UBound(Origin) Step 1

]Result = ResPush(Result, Origin(i1))

]Next

]Return Result

]End Function

文章標籤
全站熱搜
創作者介紹
創作者 GPhettoH 的頭像
GPhettoH

歇息,等待明日的天空

GPhettoH 發表在 痞客邦 留言(0) 人氣(15)