fix: compiler error and reset root (#570)

pull/574/head
nuomi1 1 year ago committed by GitHub
parent be8912073e
commit 9611a8f135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,7 +12,7 @@ func bucketSort(nums: inout [Double]) {
// 1. // 1.
for num in nums { for num in nums {
// [0, 1)使 num * k [0, k-1] // [0, 1)使 num * k [0, k-1]
let i = Int(num * k) let i = Int(num * Double(k))
// num i // num i
buckets[i].append(num) buckets[i].append(num)
} }

@ -123,7 +123,7 @@ class BinarySearchTree {
// = 0 / 1 child = null / // = 0 / 1 child = null /
let child = cur?.left != nil ? cur?.left : cur?.right let child = cur?.left != nil ? cur?.left : cur?.right
// cur // cur
if cur != root { if cur !== root {
if pre?.left === cur { if pre?.left === cur {
pre?.left = child pre?.left = child
} else { } else {
@ -131,7 +131,7 @@ class BinarySearchTree {
} }
} else { } else {
// //
root = cur; root = child
} }
} }
// = 2 // = 2

Loading…
Cancel
Save