简体   繁体   中英

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.

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. Also, the removeFirst method with a string parameter is just removes the first element and returns that node. This is however an overloaded method so the only purpose of String s is to point to which method to use. 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总是相同的,所以将该变量向上移动到循环后面

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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