首先在窗體上添加Button1,ListBox1,下面是完整代碼
專注于為中小企業(yè)提供成都網(wǎng)站建設、網(wǎng)站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)興山免費做網(wǎng)站提供優(yōu)質的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉變。
Public?Class?Form1
Public?Sub?BubbleSort(ByVal?arr()?As?Integer)?'冒泡法排序
Dim?temp?As?Double
Dim?i,?j?As?Integer
For?i?=?0?To?arr.GetUpperBound(0)?-?1
For?j?=?i?+?1?To?arr.GetUpperBound(0)?-?1
If?arr(i)??arr(j)?Then
temp?=?arr(j)
arr(j)?=?arr(i)
arr(i)?=?temp
End?If
Next
Next
End?Sub
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click?'調用
Dim?arr()?As?Integer?=?{55,?22,?33,?11,?77,?88}
BubbleSort(arr)?'調用排序過程
Me.ListBox1.Items.Clear()
For?i?=?0?To?arr.GetUpperBound(0)?-?1?'顯示排序后結果
Me.ListBox1.Items.Add(arr(i).ToString)
Next
End?Sub
End?Class
Dim d() As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim T As Integer
n = Val(InputBox("請輸入n,確定數(shù)組的元素個數(shù)"))
ReDim d(n)
'用隨機函數(shù)生成正整數(shù)數(shù)組
Randomize
For i = 1 To n
d(i) = Int(Rnd * 100 + 1)
Next i
'輸出
For i = 1 To n
Print d(i),
Next i
'從小到大排序
For i = 1 To n - 1
For j = i + 1 To n
If d(i) d(j) Then
T = d(i)
d(i) = d(j)
d(j) = T
End If
Next j
Next i
'輸出
For i = 1 To n
Print d(i),
Next i
注意:參數(shù)為動態(tài)數(shù)組;
Private Function MyF(ByRef d() As Integer)
ReDim d(4, 13) As Integer
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim MyNum(4) As Integer
For i = 1 To 4
MyNum(i) = 0
Next i
Randomize
For i = 1 To 4
For j = 1 To 13
n = Int(Rnd * 4 + 1)
Do While MyNum(n) = 13
n = Int(Rnd * 4 + 1)
Loop
d(i, j) = n
MyNum(n) = MyNum(n) + 1
Next j
Next i
End Function
public function createstringarr() as string()
return new string(){"d1","d2","d3","d4"}
end function
1、點擊VS工具。
2、打開后,新建一個Windows窗體應用程序。
3、新建完畢后,如圖所示。
4、拖動一個按鈕。
5、定義數(shù)組最常見的方法,如圖示。
6、運行后,點擊按鈕,彈出提示正常。
7、定義數(shù)組第二種方法,屬于動態(tài)的方法。
8、運行后,點擊按鈕,數(shù)組成功輸出。
thr_test(i) = New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(Sub()
直接寫過程代碼
End Sub))