Option?Explicit
公司主營業(yè)務(wù):網(wǎng)站設(shè)計、成都做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)建站是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)建站推出天峻免費做網(wǎng)站回饋大家。
Function?JionNumber(a?As?Variant,?b?As?Variant,?c?As?Variant)?'a數(shù)組和b數(shù)組?合并到c數(shù)組
Dim?i?As?Integer,?j?As?Integer
ReDim?c(UBound(a)?+?UBound(b)?+?1)
For?i?=?0?To?UBound(a)
c(i)?=?a(i)
Next
For?j?=?i?To?UBound(b)?+?i
c(j)?=?b(j?-?i)
Next
End?Function
Private?Sub?SelectSort(Xarray()?As?Variant)??'選擇排序法,升序排序
Dim?i%,?j%,?k%,?t%,?Start%,?Finish%
Start?=?LBound(Xarray,?1)
Finish?=?UBound(Xarray,?1)
For?i?=?Start?To?Finish?-?1
k?=?i
For?j?=?i?+?1?To?Finish
If?Xarray(j)??Xarray(k)?Then?k?=?j??'k表示當前最大值對應的下標
Next?j
If?k??i?Then
t?=?Xarray(i)
Xarray(i)?=?Xarray(k)
Xarray(k)?=?t
End?If
Next?i
End?Sub
Private?Sub?Command1_Click()
Dim?a()?As?Variant,?b()?As?Variant,?c()?As?Variant,?d()?As?Variant,?e()?As?Variant
Dim?f()?As?Variant?'合并后的數(shù)組
Dim?ab,?abc,?abcd,?i%
a?=?Array(10,?11,?18,?19,?26,?27,?40,?41,?48,?49)
b?=?Array(1,?8,?9,?22,?23,?30,?31,?38,?39)
c?=?Array(6,?7,?14,?15,?28,?29,?36,?37,?44,?45)
d?=?Array(2,?3,?16,?17,?24,?25,?32,?33,?46,?47)
e?=?Array(4,?5,?12,?13,?20,?21,?34,?35,?42,?43)
JionNumber?a,?b,?ab?'合并數(shù)組
JionNumber?ab,?c,?abc
JionNumber?abc,?d,?abcd
JionNumber?abcd,?e,?f
Text1?=?"排序前:"??vbCrLf
For?i?=?0?To?UBound(f)
Text1?=?Text1??"?"??f(i)
Next?i
Text1?=?Text1??vbCrLf??"排序后:"??vbCrLf
SelectSort?f()?'排序
For?i?=?0?To?UBound(f)
Text1?=?Text1??"?"??f(i)
Next?i
End?Sub
Text1屬性:MultiLine?設(shè)為?True,ScrollBars設(shè)為2
合并數(shù)組沒有簡單辦法,只能一維一維的取出來,放到一新數(shù)組中。新數(shù)組維數(shù)是原兩數(shù)組維數(shù)相加。
比如兩個數(shù)組 A ,B
dim newAr() '如果兩個數(shù)組類型相同話 ,可以定義類型。
redim newAr(ubound(A)-lbound(A)+1+ubound(B)-lbound(B)+1-1) ‘由于數(shù)組定義只能用常數(shù)表達式定義維數(shù),所以用動態(tài)數(shù)組。
把兩數(shù)組項目添加到newAr 中
dim Index as integer
dim i as integer
for i=LBound(A) to UBound(A)
newAr(Index)=A(i)
Index=Index+1
next
for i=LBound(B) to UBound(B)
newAr(Index)=B(i)
Index=Index+1
next
Private Sub Command1_Click()
a = Array(1, 2, 4, 7, 9, 34, 65, 73, 78, 99, 234, 1234)
b = Array(0, 23, 33, 56, 78, 98, 99, 234, 1000, 9999)
Dim c(30)
i = 0
j = 0
k = 0
While i = UBound(a) And j = UBound(b)
If a(i) b(j) Then
c(k) = a(i)
i = i + 1
Else
c(k) = b(j)
j = j + 1
End If
k = k + 1
Wend
While i UBound(a)
c(k) = a(i)
i = i + 1: k = k + 1
Wend
While j UBound(b)
c(k) = b(j)
j = j + 1: k = k + 1
Wend
Print "原A數(shù)組:"
For i = 0 To UBound(a)
Print a(i);
Next i
Print "原B數(shù)組:"
For i = 0 To UBound(b)
Print b(i);
Next i
Print "合并后的c數(shù)組:"
For i = 0 To k
Print c(i);
If i Mod 15 = 14 Then Print
Next i
End Sub