Files
hello-algo/ru/codes/swift/chapter_tree/binary_tree.swift
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

41 lines
1.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* File: binary_tree.swift
* Created Time: 2023-01-18
* Author: nuomi1 (nuomi1@qq.com)
*/
import utils
@main
enum BinaryTree {
/* Driver Code */
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)
// Вставить узел P между n1 -> n2
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)
}
}