Trying to print out each iteration of Bubblesort to the label text to show on the screen rather than console.
I tried to assign the label text each time the array is updated but it only shows the last version of the array which is the sorted one
On screen print:
What I want to print n the label:
class ViewController: UIViewController {
@IBOutlet weak var Label2: UILabel!
public func bubbleSort<T> (_ arrays: [T], _ comparison: (T,T) -> Bool) -> [T] {
var array = arrays
for i in 0..<array.count {
for j in 1..<array.count-i {
if comparison(array[j], array[j-1]) {
let tmp = array[j-1]
array[j-1] = array[j]
array[j] = tmp
print(array) // prints the array after each iteration to the console
// inserting Label2.text = "\(array)" doesnt work as I intend it to.
}
}
}
return array
}
public func bubbleSort<T> (_ elements: [T]) -> [T] where T: Comparable {
return bubbleSort(elements, <)
}
}