This commit is contained in:
krahets
2024-05-15 19:00:27 +08:00
parent bd54cd096b
commit e434a3343c
36 changed files with 402 additions and 107 deletions

View File

@@ -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];
```

View File

@@ -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?