Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix linked_list & add gitigonre#3

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
PegasusWang merged 1 commit intoPegasusWang:masterfromEhco1996:fix-linked-list
May 29, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,3 +25,9 @@ Session.vim

# mkdocs
site/

# vscode
.vscode/

# pytest
.pytest_cache/
8 changes: 5 additions & 3 deletionsdocs/03_链表/linked_list.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 开始
Expand DownExpand Up@@ -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

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp