mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-26 19:41:26 +08:00
build
This commit is contained in:
@@ -718,17 +718,17 @@ comments: true
|
||||
```java title="my_list.java"
|
||||
/* 列表类简易实现 */
|
||||
class MyList {
|
||||
private int[] nums; // 数组(存储列表元素)
|
||||
private int capacity = 10; // 列表容量
|
||||
private int size = 0; // 列表长度(即当前元素数量)
|
||||
private int extendRatio = 2; // 每次列表扩容的倍数
|
||||
private int[] nums; // 数组(存储列表元素)
|
||||
private int capacity = 10; // 列表容量
|
||||
private int size = 0; // 列表长度(即当前元素数量)
|
||||
private int extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
/* 构造方法 */
|
||||
public MyList() {
|
||||
nums = new int[capacity];
|
||||
}
|
||||
|
||||
/* 获取列表长度(即当前元素数量)*/
|
||||
/* 获取列表长度(即当前元素数量) */
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
@@ -820,13 +820,13 @@ comments: true
|
||||
```cpp title="my_list.cpp"
|
||||
/* 列表类简易实现 */
|
||||
class MyList {
|
||||
private:
|
||||
int* nums; // 数组(存储列表元素)
|
||||
int numsCapacity = 10; // 列表容量
|
||||
int numsSize = 0; // 列表长度(即当前元素数量)
|
||||
int extendRatio = 2; // 每次列表扩容的倍数
|
||||
private:
|
||||
int *nums; // 数组(存储列表元素)
|
||||
int numsCapacity = 10; // 列表容量
|
||||
int numsSize = 0; // 列表长度(即当前元素数量)
|
||||
int extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
public:
|
||||
public:
|
||||
/* 构造方法 */
|
||||
MyList() {
|
||||
nums = new int[numsCapacity];
|
||||
@@ -907,7 +907,7 @@ comments: true
|
||||
void extendCapacity() {
|
||||
// 新建一个长度为 size * extendRatio 的数组,并将原数组拷贝到新数组
|
||||
int newCapacity = capacity() * extendRatio;
|
||||
int* tmp = nums;
|
||||
int *tmp = nums;
|
||||
nums = new int[newCapacity];
|
||||
// 将原数组中的所有元素复制到新数组
|
||||
for (int i = 0; i < size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user