Błąd w swift params

0

Próbuję przepisac bubble sorta do swifta i rzuca mi taki error

main.swift:19:28: error: missing argument labels 'tablica:amount:' in call
var sortResult = bubbleSort(tablica, amount)

Co robię źle?

Template:

 procedure bubbleSort( A : lista elementów do posortowania )
   n = liczba_elementów(A)
    do
     for (i = 0; i < n-1; i++) do:
       if A[i] > A[i+1] then
         swap(A[i], A[i+1])
       end if
     end for
     n = n-1
   while n > 1
 end procedure

Swift:


func bubbleSort(tablica:[Int], amount:Int) {
    var n = amount
    
    repeat {
        for i in 0...tablica.count - 1 {
            if tablica[i] > tablica[i+1] {
                
            }
        }
    } while n > 1


}

var tablica = [1,2,3,4,6]
var amount = 6

var sortResult = bubbleSort(tablica, amount)
print(sortResult)
1

Swift to nie jest C po kiego grzyba ci to amount?
Lepiej doczytaj podstawy Swift.
Poza tym bubbleSort nic nie zwraca.

Dawno nie dłubałem w Swift ale to chyba powinno być tak:

import Foundation

func bubbleSort(_ tab:[Int]) ->[Int]
{
    var result = tab
    for i in 0..<result.count - 1 {
        for j in i + 1..<result.count {
            if result[i] > result[j] {
                result.swapAt(i, j)
            }
        }
    }
    return result
}

let r = bubbleSort([3, 2, 1])
print(r)

1 użytkowników online, w tym zalogowanych: 0, gości: 1