Option
Explicit
Private
Declare
Sub
Sleep
Lib
"kernel32"
(
ByVal
dwMilliseconds
As
Long
)
Public
Sub
BubbleSort_Demo()
Dim
a()
As
Variant
With
Tabelle1.Range(
"A1:A10"
)
.Formula =
"=RANDBETWEEN(0,100)"
.Copy
.PasteSpecial xlPasteValues
Application.CutCopyMode =
False
a = .Value()
Call
BubbleSort(a, .Cells)
Erase
a
End
With
Call
MsgBox(
"Fertig"
, vbInformation)
End
Sub
Private
Sub
BubbleSort(Arg()
As
Variant
, Output
As
Excel.Range)
Dim
i
As
Long
Dim
j
As
Long
Dim
t
As
Variant
Output.Worksheet.Activate
For
i = UBound(Arg) - LBound(Arg)
To
LBound(Arg)
Step
-1
For
j = LBound(Arg)
To
i
If
Arg(j, 1) > Arg(j + 1, 1)
Then
t = Arg(j, 1)
Arg(j, 1) = Arg(j + 1, 1)
Arg(j + 1, 1) = t
Output.Cells(j).
Select
Call
Sleep(1000)
End
If
Output.Value() = Arg
Next
j
Next
i
End
Sub