mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-27 12:22:45 +08:00
feat: add the section of Graph Traversal (#367)
* Graph dev * Add the section of Graph Traversal. * Add missing Vertex.java * Add mkdocs.yml * Update numbering * Fix indentation and update array.md
This commit is contained in:
@ -14,7 +14,7 @@ comments: true
|
||||
|
||||
观察上图,我们发现 **数组首元素的索引为 $0$** 。你可能会想,这并不符合日常习惯,首个元素的索引为什么不是 $1$ 呢,这不是更加自然吗?我认同你的想法,但请先记住这个设定,后面讲内存地址计算时,我会尝试解答这个问题。
|
||||
|
||||
**数组有多种初始化写法**。根据实际需要,选代码最短的那一种就好。
|
||||
**数组初始化**。一般会用到无初始值、给定初始值两种写法,可根据需求选取。在不给定初始值的情况下,一般所有元素会被初始化为默认值 $0$ 。
|
||||
|
||||
=== "Java"
|
||||
|
||||
@ -28,8 +28,12 @@ comments: true
|
||||
|
||||
```cpp title="array.cpp"
|
||||
/* 初始化数组 */
|
||||
int* arr = new int[5];
|
||||
int* nums = new int[5] { 1, 3, 2, 5, 4 };
|
||||
// 存储在栈上
|
||||
int arr[5];
|
||||
int nums[5] { 1, 3, 2, 5, 4 };
|
||||
// 存储在堆上
|
||||
int* arr1 = new int[5];
|
||||
int* nums1 = new int[5] { 1, 3, 2, 5, 4 };
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
|
Reference in New Issue
Block a user