'本来满怀信心,结果被一个小问题(平时很不在意)给难住了
'就是基础问题,公司要求写个排序的算法(我平时老是拈人家的来用)
'这应聘的结果就是不言而喻的
'吸取的教训是:一定要注重基础的夯实工作,不然就是轻飘飘的,浮的
' 这里给大家带来这样一段我的故事,望大家引以为戒
'回来就仔细拜读一个叫 马大哈 的算法
'自己又重新写作,写来了我的冒泡排序法
'其中独立了 冒泡函数
'大家可以拈来用,但更期望的把自己的基础夯实
'有空的时候去看看我的小屋,可能会有你意想不到的收获
'石陆软件屋
'http://www.cnng.net
程序代码: | [ 复制代码 ] |
Option Explicit
'石陆软件屋
'http://www.cnng.net
Dim aa() As String, bb() As Double
Sub BubbleSort(List() As Double) '冒泡排序算法
Dim First As Double, Last As Double '开始,结束
Dim i As Integer, j As Integer
Dim Temp As Double ' 交换位置的临时变量
First = LBound(List)
Last = UBound(List)
For i = First To Last - 1
For j = i + 1 To Last
If List(i) > List(j) Then '如果这个数大于下一个数
Temp = List(j) '交换位置
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i
End Sub
Private Sub Command1_Click()
Dim i As Long
aa = Split(Text1.Text, ",") '取得操作数
ReDim bb(UBound(aa))
For i = 0 To UBound(aa)
bb(i) = CDbl(aa(i)) '转换为数字类型
Next
BubbleSort bb '调用排序算法函数
Text2.Text = ""
For i = 0 To UBound(bb) '显示结果
Text2.Text = Text2.Text & " <" & bb(i)
Next
End Sub
Private Sub Form_Load()
Text1.Text = "1,2,5,4,8,7,1.2,3.6,78"
End Sub
'石陆软件屋
'http://www.cnng.net
Dim aa() As String, bb() As Double
Sub BubbleSort(List() As Double) '冒泡排序算法
Dim First As Double, Last As Double '开始,结束
Dim i As Integer, j As Integer
Dim Temp As Double ' 交换位置的临时变量
First = LBound(List)
Last = UBound(List)
For i = First To Last - 1
For j = i + 1 To Last
If List(i) > List(j) Then '如果这个数大于下一个数
Temp = List(j) '交换位置
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i
End Sub
Private Sub Command1_Click()
Dim i As Long
aa = Split(Text1.Text, ",") '取得操作数
ReDim bb(UBound(aa))
For i = 0 To UBound(aa)
bb(i) = CDbl(aa(i)) '转换为数字类型
Next
BubbleSort bb '调用排序算法函数
Text2.Text = ""
For i = 0 To UBound(bb) '显示结果
Text2.Text = Text2.Text & " <" & bb(i)
Next
End Sub
Private Sub Form_Load()
Text1.Text = "1,2,5,4,8,7,1.2,3.6,78"
End Sub
相关链接:vb | 冒泡排序 | 夯实基础
[本日志由 admin 于 2013-11-01 10:55 PM 编辑]
引用通告地址 (0):
http://www.cnng.net/blog/trackback.asp?tbID=48
http://www.cnng.net/blog/trackback.asp?tbID=48&CP=GBK
http://www.cnng.net/blog/trackback.asp?tbID=48
http://www.cnng.net/blog/trackback.asp?tbID=48&CP=GBK