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 )
}
}