简体   繁体   English

Java在跳过列表中实现删除方法

[英]Java implementing the delete methid in a skip list

The delete method for my skip list is going in an infinite loop! 我的跳过列表的delete方法陷入无限循环! I followed the pseudo code from this website http://www.mathcs.emory.edu/~cheung/Courses/323/Syllabus/Map/skip-list-impl.html . 我遵循了该网站http://www.mathcs.emory.edu/~cheung/Courses/323/Syllabus/Map/skip-list-impl.html上的伪代码。 The other methods seems to be working fine except the delete. 除删除外,其他方法似乎运行良好。 This is my code: 这是我的代码:

public void delete(String k) {
    SkipListEntry p = findEntry(k);

    if (p.key != k) {
        return; // Not found, don't remove
    }

    while (p != null) {
        //need to delete the entry from each list using the "up" or "down" links
        p.left.right = p.right;
        p.right.left = p.left;  
    }
}

This is my entire code http://pastebin.com/StJRzixN 这是我的整个代码http://pastebin.com/StJRzixN
Thanks 谢谢

You're missing a step in delete . 您缺少delete的步骤。

Before the recursive call, you need to assign p the value of p.up . 在递归调用之前,您需要为p分配p.up的值。

Otherwise, you sit on the lowest tiered p and just keep adjusting the neighbors' right and left pointers. 否则,你坐在最低分层p ,只是不断调整邻居的rightleft指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM