mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-09 05:56:06 +00:00
Bug fixes to C code.
This commit is contained in:
@@ -82,5 +82,7 @@ int main() {
|
||||
int index = find(n0, 2);
|
||||
printf("链表中值为 2 的节点的索引 = %d\r\n", index);
|
||||
|
||||
// 释放内存
|
||||
freeMemoryLinkedList(n0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ void insert(MyList *nums, int index, int num) {
|
||||
|
||||
/* 删除元素 */
|
||||
// 注意:stdio.h 占用了 remove 关键词
|
||||
int removeNum(MyList *nums, int index) {
|
||||
int removeItem(MyList *nums, int index) {
|
||||
assert(index >= 0 && index < size(nums));
|
||||
int num = nums->arr[index];
|
||||
for (int i = index; i < size(nums) - 1; i++) {
|
||||
@@ -133,7 +133,7 @@ int main() {
|
||||
printArray(toArray(nums), size(nums));
|
||||
|
||||
/* 删除元素 */
|
||||
removeNum(nums, 3);
|
||||
removeItem(nums, 3);
|
||||
printf("删除索引 3 处的元素,得到 nums = ");
|
||||
printArray(toArray(nums), size(nums));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user