'雙向排序
Public Class Form1
Dim counter = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'雙向排序 - 一次取得剩餘未處理部份的最大最小值
Dim n() = {9, 8, 7, 6, 5, 4, 3, 2, 10, 1}
Dim i1 = 0
Dim i2 = n.Length - 1
While i1 < i2
Dim j1 = i1 + 1
Dim j2 = i2 - 1
While j1 <= n.Length - 1
If n(i1) > n(j1) Then
change(n(i1), n(j1))
End If
If n(i2) < n(j2) Then
change(n(i2), n(j2))
End If
j1 = j1 + 1
j2 = j2 - 1
End While
i1 = i1 + 1
i2 = i2 - 1
End While
Dim str1 = ""
For i = 0 To n.Length - 1
str1 = str1 & n(i) & Space(3)
Next
str1 = str1 & vbNewLine & "交換:" & counter & "次 " & vbNewLine
'單向排序
counter = 0
Dim n1() = {9, 8, 7, 6, 5, 4, 3, 2, 10, 1}
Dim f1 = 0
While f1 <= n.Length - 1 - 1
Dim g1 = f1 + 1
While g1 <= n.Length - 1
If n1(f1) > n1(g1) Then
change(n1(f1), n1(g1))
End If
g1 = g1 + 1
End While
f1 = f1 + 1
End While
For i = 0 To n.Length - 1
str1 = str1 & n1(i) & Space(3)
Next
str1 = str1 & vbNewLine & "交換:" & counter & "次 " & vbNewLine
MsgBox(str1)
End
End Sub
Sub change(ByRef x, ByRef y)
Dim t = x
x = y
y = t
counter = counter + 1
End Sub
End Class
標籤雲
visual basic 2008
(157)
訊息分享
(111)
Visual Studio 2008
(64)
wpf
(37)
每日一句
(35)
cpp
(30)
python
(26)
Silverlight
(22)
C++
(18)
Network Security
(15)
全國技藝競竇
(14)
好文分享
(11)
.Net
(10)
Blogger
(10)
名詞解釋
(10)
研討會
(10)
Excel
(9)
書籍介紹
(9)
每日一小品
(9)
電腦黑白講
(8)
Visual Studio 201X
(7)
分享
(7)
網頁設計
(7)
CSS
(5)
Algorithm
(4)
Network
(3)
PHP
(3)
Access
(2)
SA
(2)
VB.Net
(2)
VBA
(2)
WireShark
(2)
Word
(2)
php html
(2)
其他好東東
(2)
分類整理
(2)
Asp.Net
(1)
Batch
(1)
Blockly
(1)
IT News
(1)
OpenAI
(1)
SE
(1)
W7
(1)
Writer
(1)
app inv2
(1)
dfs
(1)
vex vr sample
(1)
影像處理練習
(1)
黑白講
(1)
2010年10月19日 星期二
雙向排序
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言