Skip to content

Commit

Permalink
230th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Oct 19, 2024
1 parent 5b0aa09 commit 906622f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ pnpm test twoSum.test.ts
- [堆疊 (Stack)](./algorithms/stack/README.md)
- [佇列 (Queue)](./algorithms/queue/README.md)
- [雜湊表 (Hash Table)](./algorithms/hash-table/README.md)
- 樹 (Tree)
- [樹 (Tree)](./algorithms/tree/README.md)
- [堆積 (Heap)](./algorithms/heap/README.md)
- [圖 (Graph)](./algorithms/graph/README.md)
- 字典樹 (Trie)
Expand Down
41 changes: 41 additions & 0 deletions algorithms/heap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

父節點的值總是小於或等於其子節點的值。

```ts
[1, 3, 6, 5, 9, 8, 15];
```

```mermaid
graph TD
0[1] --> 1[3]
0 --> 2[6]
1 --> 3[5]
1 --> 4[9]
2 --> 5[8]
2 --> 6[15]
```

```ts
type Comparator<T> = (a: T, b: T) => number;

Expand Down Expand Up @@ -31,6 +45,20 @@ const minHeap = new Heap<number>(Heap.minComparator);

父節點的值總是大於或等於其子節點的值。

```ts
[15, 9, 8, 1, 3, 6, 5];
```

```mermaid
graph TD
0[15] --> 1[9]
0 --> 2[8]
1 --> 3[1]
1 --> 4[3]
2 --> 5[6]
2 --> 6[5]
```

```ts
type Comparator<T> = (a: T, b: T) => number;

Expand All @@ -47,9 +75,22 @@ class Heap<T> {
if (b < a) return -1;
return 0;
}

// 元素入堆積
push(value: T): void {
//
}
}
```

```ts
const maxHeap = new Heap<number>(Heap.maxComparator);

maxHeap.push(15);
maxHeap.push(9);
maxHeap.push(8);
maxHeap.push(1);
maxHeap.push(3);
maxHeap.push(6);
maxHeap.push(5);
```
21 changes: 21 additions & 0 deletions algorithms/tree/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 樹 (Tree)

## 二元樹 (Binary Tree)

```ts
class TreeNode<T> {
val: T;
left: TreeNode<T> | null;
right: TreeNode<T> | null;

constructor(val: T, left: TreeNode<T> | null = null, right: TreeNode<T> | null = null) {
this.val = val;
this.left = left;
this.right = right;
}
}
```

```ts
const n1 = new TreeNode(1);
```

0 comments on commit 906622f

Please sign in to comment.