mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-02 18:44:22 +00:00
build
This commit is contained in:
@@ -1963,8 +1963,7 @@ comments: true
|
||||
impl MyList {
|
||||
/* 构造方法 */
|
||||
pub fn new(capacity: usize) -> Self {
|
||||
let mut vec = Vec::new();
|
||||
vec.resize(capacity, 0);
|
||||
let mut vec = vec![0; capacity];
|
||||
Self {
|
||||
arr: vec,
|
||||
capacity,
|
||||
@@ -2036,7 +2035,7 @@ comments: true
|
||||
};
|
||||
let num = self.arr[index];
|
||||
// 将将索引 index 之后的元素都向前移动一位
|
||||
for j in (index..self.size - 1) {
|
||||
for j in index..self.size - 1 {
|
||||
self.arr[j] = self.arr[j + 1];
|
||||
}
|
||||
// 更新元素数量
|
||||
@@ -2055,7 +2054,7 @@ comments: true
|
||||
}
|
||||
|
||||
/* 将列表转换为数组 */
|
||||
pub fn to_array(&mut self) -> Vec<i32> {
|
||||
pub fn to_array(&self) -> Vec<i32> {
|
||||
// 仅转换有效长度范围内的列表元素
|
||||
let mut arr = Vec::new();
|
||||
for i in 0..self.size {
|
||||
|
||||
Reference in New Issue
Block a user