You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/* *
* F i l e : b i n a r y _ t r e e . s w i f t
* C r e a t e d T i m e : 2 0 2 3 - 0 1 - 1 8
* A u t h o r : n u o m i 1 ( n u o m i 1 @ q q . c o m )
*/
import utils
@ main
enum BinaryTree {
/* D r i v e r C o d e */
static func main ( ) {
/* 初 始 化 二 元 樹 */
// 初 始 化 節 點
let n1 = TreeNode ( x : 1 )
let n2 = TreeNode ( x : 2 )
let n3 = TreeNode ( x : 3 )
let n4 = TreeNode ( x : 4 )
let n5 = TreeNode ( x : 5 )
// 構 建 節 點 之 間 的 引 用 ( 指 標 )
n1 . left = n2
n1 . right = n3
n2 . left = n4
n2 . right = n5
print ( " \n 初始化二元樹 \n " )
PrintUtil . printTree ( root : n1 )
/* 插 入 與 刪 除 節 點 */
let P = TreeNode ( x : 0 )
// 在 n 1 - > n 2 中 間 插 入 節 點 P
n1 . left = P
P . left = n2
print ( " \n 插入節點 P 後 \n " )
PrintUtil . printTree ( root : n1 )
// 刪 除 節 點 P
n1 . left = n2
print ( " \n 刪除節點 P 後 \n " )
PrintUtil . printTree ( root : n1 )
}
}