Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Swaping
#6
This is the principle of sorting numbers in a one-dimensional array as I use it. There are better procedures, but hopefully this will help.

Code: (Select All)
'vygeneruju nahodna cisla
Dim A(100) As Long
For bb = 0 To 100
    Randomize Timer
    A(bb) = 32768 * (1 + bb * Rnd)
Next

'udelam druhe prazdne pole stejne velikosti pro vysledky
Dim B(100) As Long

'porovnam to
For komplet = 0 To 100
    hodnota = 0
    For s = 0 To 100
        If A(s) > -1 Then 'pokud tato hodnota jeste nebyla prirazena - prirazene hodnoty nastavuji na -1 abych jednu hodnotu neulozil vicekrat
            If hodnota < A(s) Then hodnota = A(s): zaznam = s
        End If
    Next s
    B(komplet) = hodnota
    A(zaznam) = -1
Next komplet

'vypis
For v = 0 To 100
    Print "zaznam:"; Str$(v); " - "; B(v)
    Sleep
Next


Reply


Messages In This Thread
Swaping - by CSslymer - 03-05-2023, 05:06 PM
RE: Swaping - by mnrvovrfc - 03-05-2023, 05:17 PM
RE: Swaping - by vince - 03-05-2023, 05:27 PM
RE: Swaping - by Petr - 03-05-2023, 05:27 PM
RE: Swaping - by Petr - 03-05-2023, 05:30 PM
RE: Swaping - by Petr - 03-05-2023, 05:55 PM
RE: Swaping - by bplus - 03-05-2023, 06:43 PM
RE: Swaping - by CSslymer - 03-06-2023, 05:11 AM
RE: Swaping - by mnrvovrfc - 03-05-2023, 07:52 PM
RE: Swaping - by vince - 03-06-2023, 08:14 AM
RE: Swaping - by bplus - 03-06-2023, 04:39 PM



Users browsing this thread: 1 Guest(s)