build
This commit is contained in:
parent
263c979237
commit
881ece517f
@ -1328,6 +1328,8 @@ comments: true
|
||||
int extendRatio; // 列表每次扩容的倍数
|
||||
};
|
||||
|
||||
typedef struct myList myList;
|
||||
|
||||
/* 构造函数 */
|
||||
myList *newMyList() {
|
||||
myList *list = malloc(sizeof(myList));
|
||||
|
@ -14,8 +14,8 @@ comments: true
|
||||
|
||||
=== "Java"
|
||||
|
||||
```java title="preorder_find_nodes.java"
|
||||
/* 前序遍历 */
|
||||
```java title="preorder_traversal_i_compact.java"
|
||||
/* 前序遍历:例题一 */
|
||||
void preOrder(TreeNode root) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@ -31,8 +31,8 @@ comments: true
|
||||
|
||||
=== "C++"
|
||||
|
||||
```cpp title="preorder_find_nodes.cpp"
|
||||
/* 前序遍历 */
|
||||
```cpp title="preorder_traversal_i_compact.cpp"
|
||||
/* 前序遍历:例题一 */
|
||||
void preOrder(TreeNode *root) {
|
||||
if (root == nullptr) {
|
||||
return;
|
||||
@ -48,9 +48,9 @@ comments: true
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title="preorder_find_nodes.py"
|
||||
```python title="preorder_traversal_i_compact.py"
|
||||
def pre_order(root: TreeNode) -> None:
|
||||
"""前序遍历"""
|
||||
"""前序遍历:例题一"""
|
||||
if root is None:
|
||||
return
|
||||
if root.val == 7:
|
||||
@ -62,32 +62,32 @@ comments: true
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title="preorder_find_nodes.go"
|
||||
```go title="preorder_traversal_i_compact.go"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript title="preorder_find_nodes.js"
|
||||
```javascript title="preorder_traversal_i_compact.js"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
|
||||
```typescript title="preorder_find_nodes.ts"
|
||||
```typescript title="preorder_traversal_i_compact.ts"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="preorder_find_nodes.c"
|
||||
```c title="preorder_traversal_i_compact.c"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="preorder_find_nodes.cs"
|
||||
/* 前序遍历 */
|
||||
```csharp title="preorder_traversal_i_compact.cs"
|
||||
/* 前序遍历:例题一 */
|
||||
void preOrder(TreeNode root)
|
||||
{
|
||||
if (root == null)
|
||||
@ -106,13 +106,13 @@ comments: true
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="preorder_find_nodes.swift"
|
||||
```swift title="preorder_traversal_i_compact.swift"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="preorder_find_nodes.zig"
|
||||
```zig title="preorder_traversal_i_compact.zig"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
@ -134,8 +134,8 @@ comments: true
|
||||
|
||||
=== "Java"
|
||||
|
||||
```java title="preorder_find_paths.java"
|
||||
/* 前序遍历 */
|
||||
```java title="preorder_traversal_ii_compact.java"
|
||||
/* 前序遍历:例题二 */
|
||||
void preOrder(TreeNode root) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@ -155,8 +155,8 @@ comments: true
|
||||
|
||||
=== "C++"
|
||||
|
||||
```cpp title="preorder_find_paths.cpp"
|
||||
/* 前序遍历 */
|
||||
```cpp title="preorder_traversal_ii_compact.cpp"
|
||||
/* 前序遍历:例题二 */
|
||||
void preOrder(TreeNode *root) {
|
||||
if (root == nullptr) {
|
||||
return;
|
||||
@ -176,9 +176,9 @@ comments: true
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title="preorder_find_paths.py"
|
||||
```python title="preorder_traversal_ii_compact.py"
|
||||
def pre_order(root: TreeNode) -> None:
|
||||
"""前序遍历"""
|
||||
"""前序遍历:例题二"""
|
||||
if root is None:
|
||||
return
|
||||
# 尝试
|
||||
@ -194,32 +194,32 @@ comments: true
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title="preorder_find_paths.go"
|
||||
```go title="preorder_traversal_ii_compact.go"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript title="preorder_find_paths.js"
|
||||
```javascript title="preorder_traversal_ii_compact.js"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
|
||||
```typescript title="preorder_find_paths.ts"
|
||||
```typescript title="preorder_traversal_ii_compact.ts"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="preorder_find_paths.c"
|
||||
```c title="preorder_traversal_ii_compact.c"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="preorder_find_paths.cs"
|
||||
/* 前序遍历 */
|
||||
```csharp title="preorder_traversal_ii_compact.cs"
|
||||
/* 前序遍历:例题二 */
|
||||
void preOrder(TreeNode root)
|
||||
{
|
||||
if (root == null)
|
||||
@ -242,13 +242,13 @@ comments: true
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="preorder_find_paths.swift"
|
||||
```swift title="preorder_traversal_ii_compact.swift"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="preorder_find_paths.zig"
|
||||
```zig title="preorder_traversal_ii_compact.zig"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
@ -297,8 +297,8 @@ comments: true
|
||||
|
||||
=== "Java"
|
||||
|
||||
```java title="preorder_find_constrained_paths.java"
|
||||
/* 前序遍历 */
|
||||
```java title="preorder_traversal_iii_compact.java"
|
||||
/* 前序遍历:例题三 */
|
||||
void preOrder(TreeNode root) {
|
||||
// 剪枝
|
||||
if (root == null || root.val == 3) {
|
||||
@ -319,8 +319,8 @@ comments: true
|
||||
|
||||
=== "C++"
|
||||
|
||||
```cpp title="preorder_find_constrained_paths.cpp"
|
||||
/* 前序遍历 */
|
||||
```cpp title="preorder_traversal_iii_compact.cpp"
|
||||
/* 前序遍历:例题三 */
|
||||
void preOrder(TreeNode *root) {
|
||||
// 剪枝
|
||||
if (root == nullptr || root->val == 3) {
|
||||
@ -341,9 +341,9 @@ comments: true
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title="preorder_find_constrained_paths.py"
|
||||
```python title="preorder_traversal_iii_compact.py"
|
||||
def pre_order(root: TreeNode) -> None:
|
||||
"""前序遍历"""
|
||||
"""前序遍历:例题三"""
|
||||
# 剪枝
|
||||
if root is None or root.val == 3:
|
||||
return
|
||||
@ -360,32 +360,32 @@ comments: true
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title="preorder_find_constrained_paths.go"
|
||||
```go title="preorder_traversal_iii_compact.go"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript title="preorder_find_constrained_paths.js"
|
||||
```javascript title="preorder_traversal_iii_compact.js"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
|
||||
```typescript title="preorder_find_constrained_paths.ts"
|
||||
```typescript title="preorder_traversal_iii_compact.ts"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="preorder_find_constrained_paths.c"
|
||||
```c title="preorder_traversal_iii_compact.c"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="preorder_find_constrained_paths.cs"
|
||||
/* 前序遍历 */
|
||||
```csharp title="preorder_traversal_iii_compact.cs"
|
||||
/* 前序遍历:例题三 */
|
||||
void preOrder(TreeNode root)
|
||||
{
|
||||
// 剪枝
|
||||
@ -409,13 +409,13 @@ comments: true
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="preorder_find_constrained_paths.swift"
|
||||
```swift title="preorder_traversal_iii_compact.swift"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="preorder_find_constrained_paths.zig"
|
||||
```zig title="preorder_traversal_iii_compact.zig"
|
||||
[class]{}-[func]{preOrder}
|
||||
```
|
||||
|
||||
@ -471,7 +471,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "Java"
|
||||
|
||||
```java title="backtrack_find_constrained_paths.java"
|
||||
```java title="preorder_traversal_iii_template.java"
|
||||
/* 判断当前状态是否为解 */
|
||||
boolean isSolution(List<TreeNode> state) {
|
||||
return !state.isEmpty() && state.get(state.size() - 1).val == 7;
|
||||
@ -497,7 +497,7 @@ def backtrack(state, choices, res):
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
|
||||
/* 回溯算法 */
|
||||
/* 回溯算法:例题三 */
|
||||
void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {
|
||||
// 检查是否为解
|
||||
if (isSolution(state)) {
|
||||
@ -521,7 +521,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "C++"
|
||||
|
||||
```cpp title="backtrack_find_constrained_paths.cpp"
|
||||
```cpp title="preorder_traversal_iii_template.cpp"
|
||||
/* 判断当前状态是否为解 */
|
||||
bool isSolution(vector<TreeNode *> &state) {
|
||||
return !state.empty() && state.back()->val == 7;
|
||||
@ -547,7 +547,7 @@ def backtrack(state, choices, res):
|
||||
state.pop_back();
|
||||
}
|
||||
|
||||
/* 回溯算法 */
|
||||
/* 回溯算法:例题三 */
|
||||
void backtrack(vector<TreeNode *> &state, vector<TreeNode *> &choices, vector<vector<TreeNode *>> &res) {
|
||||
// 检查是否为解
|
||||
if (isSolution(state)) {
|
||||
@ -572,7 +572,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title="backtrack_find_constrained_paths.py"
|
||||
```python title="preorder_traversal_iii_template.py"
|
||||
def is_solution(state: list[TreeNode]) -> bool:
|
||||
"""判断当前状态是否为解"""
|
||||
return state and state[-1].val == 7
|
||||
@ -594,7 +594,7 @@ def backtrack(state, choices, res):
|
||||
state.pop()
|
||||
|
||||
def backtrack(state: list[TreeNode], choices: list[TreeNode], res: list[list[TreeNode]]):
|
||||
"""回溯算法"""
|
||||
"""回溯算法:例题三"""
|
||||
# 检查是否为解
|
||||
if is_solution(state):
|
||||
# 记录解
|
||||
@ -613,7 +613,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title="backtrack_find_constrained_paths.go"
|
||||
```go title="preorder_traversal_iii_template.go"
|
||||
[class]{}-[func]{isSolution}
|
||||
|
||||
[class]{}-[func]{recordSolution}
|
||||
@ -629,7 +629,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript title="backtrack_find_constrained_paths.js"
|
||||
```javascript title="preorder_traversal_iii_template.js"
|
||||
[class]{}-[func]{isSolution}
|
||||
|
||||
[class]{}-[func]{recordSolution}
|
||||
@ -645,7 +645,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "TypeScript"
|
||||
|
||||
```typescript title="backtrack_find_constrained_paths.ts"
|
||||
```typescript title="preorder_traversal_iii_template.ts"
|
||||
[class]{}-[func]{isSolution}
|
||||
|
||||
[class]{}-[func]{recordSolution}
|
||||
@ -661,7 +661,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="backtrack_find_constrained_paths.c"
|
||||
```c title="preorder_traversal_iii_template.c"
|
||||
[class]{}-[func]{isSolution}
|
||||
|
||||
[class]{}-[func]{recordSolution}
|
||||
@ -677,7 +677,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="backtrack_find_constrained_paths.cs"
|
||||
```csharp title="preorder_traversal_iii_template.cs"
|
||||
/* 判断当前状态是否为解 */
|
||||
bool isSolution(List<TreeNode> state)
|
||||
{
|
||||
@ -708,7 +708,7 @@ def backtrack(state, choices, res):
|
||||
state.RemoveAt(state.Count - 1);
|
||||
}
|
||||
|
||||
/* 回溯算法 */
|
||||
/* 回溯算法:例题三 */
|
||||
void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res)
|
||||
{
|
||||
// 检查是否为解
|
||||
@ -737,7 +737,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="backtrack_find_constrained_paths.swift"
|
||||
```swift title="preorder_traversal_iii_template.swift"
|
||||
[class]{}-[func]{isSolution}
|
||||
|
||||
[class]{}-[func]{recordSolution}
|
||||
@ -753,7 +753,7 @@ def backtrack(state, choices, res):
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="backtrack_find_constrained_paths.zig"
|
||||
```zig title="preorder_traversal_iii_template.zig"
|
||||
[class]{}-[func]{isSolution}
|
||||
|
||||
[class]{}-[func]{recordSolution}
|
||||
|
@ -956,6 +956,8 @@ $$
|
||||
UT_hash_handle hh; // 基于 uthash.h 实现
|
||||
};
|
||||
|
||||
typedef struct hashTable hashTable;
|
||||
|
||||
/* 线性阶 */
|
||||
void linear(int n) {
|
||||
// 长度为 n 的数组占用 O(n) 空间
|
||||
@ -1006,7 +1008,7 @@ $$
|
||||
nodes.Add(new ListNode(i));
|
||||
}
|
||||
// 长度为 n 的哈希表占用 O(n) 空间
|
||||
Dictionary<int, String> map = new();
|
||||
Dictionary<int, string> map = new();
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
map.Add(i, i.ToString());
|
||||
|
@ -674,7 +674,7 @@ comments: true
|
||||
Console.Write("顶点列表 = ");
|
||||
PrintUtil.PrintList(vertices);
|
||||
Console.WriteLine("邻接矩阵 =");
|
||||
PrintUtil.printMatrix(adjMat);
|
||||
PrintUtil.PrintMatrix(adjMat);
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -1382,8 +1382,8 @@ comments: true
|
||||
{
|
||||
List<int> tmp = new List<int>();
|
||||
foreach (Vertex vertex in entry.Value)
|
||||
tmp.Add(vertex.Val);
|
||||
Console.WriteLine(entry.Key.Val + ": [" + string.Join(", ", tmp) + "],");
|
||||
tmp.Add(vertex.val);
|
||||
Console.WriteLine(entry.Key.val + ": [" + string.Join(", ", tmp) + "],");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -970,12 +970,12 @@ $$
|
||||
=== "C#"
|
||||
|
||||
```csharp title="array_hash_map.cs"
|
||||
/* 键值对 int->String */
|
||||
/* 键值对 int->string */
|
||||
class Entry
|
||||
{
|
||||
public int key;
|
||||
public String val;
|
||||
public Entry(int key, String val)
|
||||
public string val;
|
||||
public Entry(int key, string val)
|
||||
{
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
@ -1004,7 +1004,7 @@ $$
|
||||
}
|
||||
|
||||
/* 查询操作 */
|
||||
public String? get(int key)
|
||||
public string? get(int key)
|
||||
{
|
||||
int index = hashFunc(key);
|
||||
Entry? pair = buckets[index];
|
||||
@ -1013,7 +1013,7 @@ $$
|
||||
}
|
||||
|
||||
/* 添加操作 */
|
||||
public void put(int key, String val)
|
||||
public void put(int key, string val)
|
||||
{
|
||||
Entry pair = new Entry(key, val);
|
||||
int index = hashFunc(key);
|
||||
@ -1053,9 +1053,9 @@ $$
|
||||
}
|
||||
|
||||
/* 获取所有值 */
|
||||
public List<String> valueSet()
|
||||
public List<string> valueSet()
|
||||
{
|
||||
List<String> valueSet = new();
|
||||
List<string> valueSet = new();
|
||||
foreach (Entry? pair in buckets)
|
||||
{
|
||||
if (pair != null)
|
||||
|
@ -329,6 +329,8 @@ comments: true
|
||||
UT_hash_handle hh; // 基于 uthash.h 实现
|
||||
};
|
||||
|
||||
typedef struct hashTable hashTable;
|
||||
|
||||
/* 哈希表查询 */
|
||||
hashTable *find(hashTable *h, int key) {
|
||||
hashTable *tmp;
|
||||
|
@ -1043,6 +1043,8 @@ comments: true
|
||||
struct doublyListNode *prev; // 前驱节点
|
||||
};
|
||||
|
||||
typedef struct doublyListNode doublyListNode;
|
||||
|
||||
/* 构造函数 */
|
||||
doublyListNode *newDoublyListNode(int num) {
|
||||
doublyListNode *new = (doublyListNode *)malloc(sizeof(doublyListNode));
|
||||
@ -1063,6 +1065,8 @@ comments: true
|
||||
int queSize; // 双向队列的长度
|
||||
};
|
||||
|
||||
typedef struct linkedListDeque linkedListDeque;
|
||||
|
||||
/* 构造j */
|
||||
linkedListDeque *newLinkedListDeque() {
|
||||
linkedListDeque *deque = (linkedListDeque *)malloc(sizeof(linkedListDeque));
|
||||
@ -2166,6 +2170,8 @@ comments: true
|
||||
int queCapacity; // 队列容量
|
||||
};
|
||||
|
||||
typedef struct arrayDeque arrayDeque;
|
||||
|
||||
/* 构造函数 */
|
||||
arrayDeque *newArrayDeque(int capacity) {
|
||||
arrayDeque *deque = (arrayDeque *)malloc(sizeof(arrayDeque));
|
||||
|
@ -685,6 +685,8 @@ comments: true
|
||||
int queSize;
|
||||
};
|
||||
|
||||
typedef struct linkedListQueue linkedListQueue;
|
||||
|
||||
/* 构造函数 */
|
||||
linkedListQueue *newLinkedListQueue() {
|
||||
linkedListQueue *queue = (linkedListQueue *)malloc(sizeof(linkedListQueue));
|
||||
@ -1459,6 +1461,8 @@ comments: true
|
||||
int queCapacity; // 队列容量
|
||||
};
|
||||
|
||||
typedef struct arrayQueue arrayQueue;
|
||||
|
||||
/* 构造函数 */
|
||||
arrayQueue *newArrayQueue(int capacity) {
|
||||
arrayQueue *queue = (arrayQueue *)malloc(sizeof(arrayQueue));
|
||||
|
@ -636,6 +636,8 @@ comments: true
|
||||
int size; // 栈的长度
|
||||
};
|
||||
|
||||
typedef struct linkedListStack linkedListStack;
|
||||
|
||||
/* 构造函数 */
|
||||
linkedListStack *newLinkedListStack() {
|
||||
linkedListStack *s = malloc(sizeof(linkedListStack));
|
||||
@ -1204,6 +1206,8 @@ comments: true
|
||||
int size;
|
||||
};
|
||||
|
||||
typedef struct arrayStack arrayStack;
|
||||
|
||||
/* 构造函数 */
|
||||
arrayStack *newArrayStack() {
|
||||
arrayStack *s = malloc(sizeof(arrayStack));
|
||||
|
Loading…
Reference in New Issue
Block a user