Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
C++ 字符串数组的基数排序行为不正确?_C++_String_Sorting_Radix - Fatal编程技术网

C++ 字符串数组的基数排序行为不正确?

C++ 字符串数组的基数排序行为不正确?,c++,string,sorting,radix,C++,String,Sorting,Radix,我很快就能让这个程序工作了,但我正试图让这个程序用基数排序对一组字符串进行字母排序,我在弄清楚如何 void msd(string* sortMe) { aux = new string[numElements]; //Set size of the array used to sort each character. msd(sortMe, 0, numElements, 0); } void msd(string* sortMe, int l, int r, int d)

我很快就能让这个程序工作了,但我正试图让这个程序用基数排序对一组字符串进行字母排序,我在弄清楚如何

void msd(string* sortMe)
{
    aux = new string[numElements];  //Set size of the array used to sort each character.
    msd(sortMe, 0, numElements, 0);
}

void msd(string* sortMe, int l, int r, int d) //Here I use key-indexed     counting :http://algs4.cs.princeton.edu/lectures/51DemoKeyIndexedCounting.pdf
{
    if(r < l || r == l) return; //if we get to 1 left, it is sorted
    int count[256+1]= {0};  //256 because we are using ASCII. + 1 for key-indexed counting
    for(int i =0; i < numElements; i++)
    {
         count[sortMe[i][d] + 1]++;   //For each letter found, you must put it in the ascii code + 1
    }
    for(int k = 1; k < 256; k++)    //Everything but null
    {
         count[k] += count[k-1];     //Get cumulates(everything before added together + what it is)
    }
    for(int i =0; i < numElements; i++)
    {
         aux[count[sortMe[i][d]]++] = sortMe[i]; //using your count array, you must move over elements from sortMe, to the aux array
    }
    for(int i = 0; i < numElements; i++)
    {
         sortMe[i] = aux[i];      //Then you must copy the elements from the aux array back to the main array.
    }
    for(int i = 0; i< numElements; i++)
    {
         cout<< aux[i]<< endl;
    }
    for(int i = 0; i < 255; i++)
    {
         msd(sortMe, l + count[i], l+ count[i+1], d+1); //You must then call recursively. The count array when finished, will give you what indexes(sub arrays to sort) you must sort between. Also, you are moving to the next character in the string(d)
    }
}
void msd(字符串*sortMe)
{
aux=新字符串[numElements];//设置用于对每个字符进行排序的数组大小。
msd(sortMe,0,Numements,0);
}
void msd(string*sortMe,int l,int r,int d)//这里我使用键索引计数:http://algs4.cs.princeton.edu/lectures/51DemoKeyIndexedCounting.pdf
{
如果(r(inti=0;i