-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linked_list完成delete方法,linked_list_test新增delete测试用例 #38
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #38 +/- ##
==========================================
+ Coverage 88.54% 89.76% +1.21%
==========================================
Files 7 7
Lines 262 293 +31
==========================================
+ Hits 232 263 +31
+ Misses 27 26 -1
- Partials 3 4 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
list/linked_list.go
Outdated
// 删除head | ||
if index == 0 { | ||
delVal = l.head.val | ||
l.head.next.prev = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这里会不会 panic?如果我只有一个元素,然后恰好被你删了,head.next 其实是 nil
list/linked_list.go
Outdated
tmp := l.tail.prev | ||
l.tail = tmp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l.tail = l.tail.prev
这样应该也可以吧?不需要 tmp
这个中间变量
list/linked_list_test.go
Outdated
{ | ||
name: "delete num to index 1", | ||
list: NewLinkedListOf[int]([]int{11, 22, 33, 44, 55}), | ||
index: 1, | ||
delVal: 22, | ||
wantLinkedList: NewLinkedListOf([]int{11, 33, 44, 55}), | ||
}, | ||
{ | ||
name: "delete num to index 2", | ||
list: NewLinkedListOf[int]([]int{11, 22, 33, 44, 55}), | ||
index: 2, | ||
delVal: 33, | ||
wantLinkedList: NewLinkedListOf([]int{11, 22, 44, 55}), | ||
}, | ||
{ | ||
name: "delete num to index 3", | ||
list: NewLinkedListOf[int]([]int{11, 22, 33, 44, 55}), | ||
index: 3, | ||
delVal: 44, | ||
wantLinkedList: NewLinkedListOf([]int{11, 22, 33, 55}), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这三个测试用例,你只需要保留一个就可以,因为它们其实都命中你删除中间结点的那一个部分。此外,你还需要提供一个额外的测试用例:只有一个元素,然后被你删掉的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这三个测试用例,你只需要保留一个就可以,因为它们其实都命中你删除中间结点的那一个部分。此外,你还需要提供一个额外的测试用例:只有一个元素,然后被你删掉的
好的
linked_list完成delete方法,linked_list_test新增delete测试用例