From 4fa41ce08a2913190f54d8c7416e52bbbaa8f2c1 Mon Sep 17 00:00:00 2001 From: machangxin Date: Sun, 18 Dec 2022 21:57:29 +0800 Subject: [PATCH] fixed clear list in Go --- codes/go/chapter_array_and_linkedlist/list_test.go | 2 +- docs/chapter_array_and_linkedlist/list.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/go/chapter_array_and_linkedlist/list_test.go b/codes/go/chapter_array_and_linkedlist/list_test.go index eedb8637c..141f83ad7 100644 --- a/codes/go/chapter_array_and_linkedlist/list_test.go +++ b/codes/go/chapter_array_and_linkedlist/list_test.go @@ -25,7 +25,7 @@ func TestList(t *testing.T) { fmt.Println("将索引 1 处的元素更新为 0 ,得到 list =", list) /* 清空列表 */ - list = []int{} + list = nil fmt.Println("清空列表后 list =", list) /* 尾部添加元素 */ diff --git a/docs/chapter_array_and_linkedlist/list.md b/docs/chapter_array_and_linkedlist/list.md index 4e177f3df..3c7a692e4 100644 --- a/docs/chapter_array_and_linkedlist/list.md +++ b/docs/chapter_array_and_linkedlist/list.md @@ -208,7 +208,7 @@ comments: true ```go title="list_test.go" /* 清空列表 */ - list = []int{} + list = nil /* 尾部添加元素 */ list = append(list, 1)