完善所以c#相关的文档和代码

This commit is contained in:
zhuzhiqing
2022-12-23 15:42:02 +08:00
parent 1646c284f6
commit a427cb1b4d
48 changed files with 4325 additions and 65 deletions

View File

@@ -97,7 +97,13 @@ comments: true
=== "C#"
```csharp title=""
/* 链表结点类 */
class TreeNode {
int val; // 结点值
TreeNode left; // 左子结点指针
TreeNode right; // 右子结点指针
TreeNode(int x) { val = x; }
}
```
结点的两个指针分别指向「左子结点 Left Child Node」和「右子结点 Right Child Node」并且称该结点为两个子结点的「父结点 Parent Node」。给定二叉树某结点将左子结点以下的树称为该结点的「左子树 Left Subtree」右子树同理。
@@ -232,7 +238,18 @@ comments: true
=== "C#"
```csharp title="binary_tree.cs"
/* 初始化二叉树 */
// 初始化结点
TreeNode n1 = new TreeNode(1);
TreeNode n2 = new TreeNode(2);
TreeNode n3 = new TreeNode(3);
TreeNode n4 = new TreeNode(4);
TreeNode n5 = new TreeNode(5);
// 构建引用指向(即指针)
n1.left = n2;
n1.right = n3;
n2.left = n4;
n2.right = n5;
```
**插入与删除结点。** 与链表类似,插入与删除结点都可以通过修改指针实现。
@@ -315,7 +332,13 @@ comments: true
=== "C#"
```csharp title="binary_tree.cs"
/* 插入与删除结点 */
TreeNode P = new TreeNode(0);
// 在 n1 -> n2 中间插入结点 P
n1.left = P;
P.left = n2;
// 删除结点 P
n1.left = n2;
```
!!! note
@@ -446,7 +469,9 @@ comments: true
=== "C#"
```csharp title=""
/* 二叉树的数组表示 */
// 使用 int?可空类型 ,就可以使用 null 来标记空位
int?[] tree = { 1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15 };
```
![array_representation_with_empty](binary_tree.assets/array_representation_with_empty.png)