简体   繁体   English

将元素从存储桶移至LinkedList,但一个元素被完全删除

[英]Moving elements from bucket to LinkedList but one element gets removed entirely

I am working on a radix sort for my computer science lab in Java, I am encountering a problem however. 我正在用Java在我的计算机科学实验室从事基数排序工作,但是我遇到了一个问题。

After putting all elements into buckets based on the value of the digits, I have a method that moves all elements from the bucket into another linked list. 根据数字的值将所有元素放入存储桶后,我有了一种将所有元素从存储桶移到另一个链表的方法。

The problem that occurs is that the movement from the bucket to the linked list results in one missing element. 发生的问题是,从存储桶到链表的移动导致缺少一个元素。 The bucket is an array of LinkedLists, pass is a linked list. 值区是LinkedLists的数组,pass是链表。 Also, the removeFirst method with a string parameter is just removes the first element and returns that node. 同样,带有字符串参数的removeFirst方法只是删除第一个元素并返回该节点。 This is however an overloaded method so the only purpose of String s is to point to which method to use. 但是,这是一个重载的方法,因此String s唯一目的是指向要使用的方法。 It serves no other purpose. 它没有其他目的。

String s = null;
for(int i = 0; i < bucket.length; i ++){
    for (int k = 0; k< bucket[i].numOfNodes();k++){
        Node temp = (bucket[i].removeFirst(s));
        pass.addToEnd(temp);

        temp = temp.getNext();
    }
}
}

因为您的tmp总是相同的,所以将该变量向上移动到循环后面

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

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