Skip to content
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

链表实现无序符号表算法错误 #1199

Open
byedo opened this issue Jun 26, 2022 · 0 comments
Open

链表实现无序符号表算法错误 #1199

byedo opened this issue Jun 26, 2022 · 0 comments

Comments

@byedo
Copy link

byedo commented Jun 26, 2022

https://github.com/CyC2018/CS-Notes/blob/master/notes/%E7%AE%97%E6%B3%95%20-%20%E7%AC%A6%E5%8F%B7%E8%A1%A8.md

@Override
public void delete(Key key) {
    if (first == null)
        return;
    if (first.key.equals(key))
        first = first.next;
    Node pre = first, cur = first.next;
    while (cur != null) {
        if (cur.key.equals(key)) {
            pre.next = cur.next;
            return;
        }
        pre = pre.next;
        cur = cur.next;
    }
}

应该改成

@Override
public void delete(Key key) {
    if (first == null)
        return;
    if (first.key.equals(key)) {
        first = first.next;
        return;
    }
    Node pre = first, cur = first.next;
    while (cur != null) {
        if (cur.key.equals(key)) {
            pre.next = cur.next;
            return;
        }
        pre = pre.next;
        cur = cur.next;
    }
}
@byedo byedo changed the title 算法错误 链表实现无序符号表算法错误 Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant