Bug fixes to C code.

This commit is contained in:
krahets
2023-11-01 05:14:22 +08:00
parent f7dd05e7a4
commit 355cc3a6b1
31 changed files with 246 additions and 219 deletions

View File

@ -26,10 +26,10 @@ public enum PrintUtil {
}
public static func printTree(root: TreeNode?) {
printTree(root: root, prev: nil, isLeft: false)
printTree(root: root, prev: nil, isRight: false)
}
private static func printTree(root: TreeNode?, prev: Trunk?, isLeft: Bool) {
private static func printTree(root: TreeNode?, prev: Trunk?, isRight: Bool) {
if root == nil {
return
}
@ -37,11 +37,11 @@ public enum PrintUtil {
var prevStr = " "
let trunk = Trunk(prev: prev, str: prevStr)
printTree(root: root?.right, prev: trunk, isLeft: true)
printTree(root: root?.right, prev: trunk, isRight: true)
if prev == nil {
trunk.str = "———"
} else if isLeft {
} else if isRight {
trunk.str = "/———"
prevStr = " |"
} else {
@ -57,7 +57,7 @@ public enum PrintUtil {
}
trunk.str = " |"
printTree(root: root?.left, prev: trunk, isLeft: false)
printTree(root: root?.left, prev: trunk, isRight: false)
}
private static func showTrunks(p: Trunk?) {