Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用节点代替整数在Java中实现基数排序_Java_Sorting_Radix Sort - Fatal编程技术网

用节点代替整数在Java中实现基数排序

用节点代替整数在Java中实现基数排序,java,sorting,radix-sort,Java,Sorting,Radix Sort,我有一个数据结构类的最终项目,我不知道该怎么做。我需要实现基数排序,并且我大部分都理解这个概念。但是到目前为止,我在网上找到的所有实现都严格地将其用于整数,我需要将其用于我创建的另一种类型Note,它是一个带有ID参数的字符串。 这是我到目前为止所做的,但不幸的是,它没有通过任何JUnit测试 package edu.drew.note; public class RadixSort implements SortInterface { public static void Radi

我有一个数据结构类的最终项目,我不知道该怎么做。我需要实现基数排序,并且我大部分都理解这个概念。但是到目前为止,我在网上找到的所有实现都严格地将其用于整数,我需要将其用于我创建的另一种类型Note,它是一个带有ID参数的字符串。 这是我到目前为止所做的,但不幸的是,它没有通过任何JUnit测试

package edu.drew.note;
public class RadixSort implements SortInterface {

     public static void Radix(Note[] note){

            // Largest place for a 32-bit int is the 1 billion's place
            for(int place=1; place <= 1000000000; place *= 10){
                // Use counting sort at each digit's place
                note = countingSort(note, place);
            }

            //return note;
        }

        private static Note[] countingSort(Note[] note, long place){ //Where the sorting actually happens
            Note[] output = new Note[note.length]; //Creating a new note that would be our output.

            int[] count = new int[10];  //Creating a counter

            for(int i=0; i < note.length; i++){ //For loop that calculates 
                int digit = getDigit(note[i].getID(), place);
                count[digit] += 1;
            }

            for(int i=1; i < count.length; i++){
                count[i] += count[i-1];
            }

            for(int i = note.length-1; i >= 0; i--){
                int digit = getDigit((note[i].getID()), place);

                output[count[digit]-1] = note[i];
                count[digit]--;
            }

            return output;

        }

        private static int getDigit(long value, long digitPlace){  //Takes value of Note[i] and i. Returns digit.
            return (int) ((value/digitPlace ) % 10);
        }


        public Note[] sort(Note[] s) {  //
             Radix(s);
             return s;
        }


        //Main Method
        public static void main(String[] args) {
            // make an array of notes
            Note q = new Note(" ", " ");
            Note n = new Note("CSCI 230 Project Plan", 
                    "Each person will number their top 5 choices.\n" +
                    "By next week, Dr. Hill will assign which piece\n" +
                    "everyone will work on.\n");
            n.tag("CSCI 230");
            n.tag("final project");

            Note[] Note = {q,n};
            //print out not id's
            System.out.println(Note + " Worked");
            //call radix
            Radix(Note);
            System.out.println(Note);
            //print out note_id's
        }

    }
包edu.draw.note;
公共类RadixSort实现SortInterface{
公共静态无效基数(注[]注){
//32位整数的最大位置是10亿位
对于(int place=1;place而不是

public Note[] sort(Note[] s) {  //
         Radix(s);
         return s;
    }
我应该用

public Note[] sort(Note[] s) {  //
        s = Radix(s);
         return s;
    }
并将
Radix
的变量类型从
void
更改为
Note[]