diff --git a/.gitignore b/.gitignore index eac36dd..e70d4d9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,9 @@ Session.vim # mkdocs site/ + +# vscode +.vscode/ + +# pytest +.pytest_cache/ \ No newline at end of file diff --git "a/docs/03_\351\223\276\350\241\250/linked_list.py" "b/docs/03_\351\223\276\350\241\250/linked_list.py" index 813ccbe..b2c7ffc 100644 --- "a/docs/03_\351\223\276\350\241\250/linked_list.py" +++ "b/docs/03_\351\223\276\350\241\250/linked_list.py" @@ -68,12 +68,13 @@ def remove(self, value): # O(n) """ prevnode = self.root # curnode = self.root.next - while curnode.next is not None: + for curnode in self.iter_node(): if curnode.value == value: prevnode.next = curnode.next del curnode self.length -= 1 - return + return 1 # 表明删除成功 + return -1 # 表明删除失败 def find(self, value): # O(n) """ 查找一个节点,返回序号,从 0 开始 @@ -117,7 +118,8 @@ def test_linked_list(): assert ll.find(2) == 2 assert ll.find(3) == -1 - ll.remove(0) + assert ll.remove(0) == 1 + assert ll.remove(3) == -1 assert len(ll) == 2 assert ll.find(0) == -1