mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-25 11:04:18 +08:00
build
This commit is contained in:
@@ -99,7 +99,12 @@ Arrays can be initialized in two ways depending on the needs: either without ini
|
||||
|
||||
```rust title="array.rs"
|
||||
/* Initialize array */
|
||||
let arr: Vec<i32> = vec![0; 5]; // [0, 0, 0, 0, 0]
|
||||
let arr: [i32; 5] = [0; 5]; // [0, 0, 0, 0, 0]
|
||||
let slice: &[i32] = &[0; 5];
|
||||
// In Rust, specifying the length ([i32; 5]) denotes an array, while not specifying it (&[i32]) denotes a slice.
|
||||
// Since Rust's arrays are designed to have compile-time fixed length, only constants can be used to specify the length.
|
||||
// Vectors are generally used as dynamic arrays in Rust.
|
||||
// For convenience in implementing the extend() method, the vector will be considered as an array here.
|
||||
let nums: Vec<i32> = vec![1, 3, 2, 5, 4];
|
||||
```
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ On the other hand, linked lists are primarily necessary for binary trees and gra
|
||||
|
||||
**Q**: Does initializing a list `res = [0] * self.size()` result in each element of `res` referencing the same address?
|
||||
|
||||
No. However, this issue arises with two-dimensional arrays, for example, initializing a two-dimensional list `res = [[0] * self.size()]` would reference the same list `[0]` multiple times.
|
||||
No. However, this issue arises with two-dimensional arrays, for example, initializing a two-dimensional list `res = [[0]] * self.size()` would reference the same list `[0]` multiple times.
|
||||
|
||||
**Q**: In deleting a node, is it necessary to break the reference to its successor node?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user