Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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_Arrays_String_Char_Quicksort - Fatal编程技术网

C语言中单词排序的快速排序算法

C语言中单词排序的快速排序算法,c,arrays,string,char,quicksort,C,Arrays,String,Char,Quicksort,在我在线课程的一个作业中,我必须使用快速排序算法对单词列表进行排序。我能对一系列数字进行排序,但不能对单词进行排序。函数IthChar接受两个参数,一个字符串和一个表示字符串索引的整数,并返回位于索引位置的字符。 例如,IthChar(“Paul”,0)-->P 以下是快速排序、交换和交换功能: void quickSort(string array[], int left, int right) { int I, J, pivot; char chI, chJ, chP

在我在线课程的一个作业中,我必须使用快速排序算法对单词列表进行排序。我能对一系列数字进行排序,但不能对单词进行排序。函数IthChar接受两个参数,一个字符串和一个表示字符串索引的整数,并返回位于索引位置的字符。
例如,IthChar(“Paul”,0)-->P

以下是快速排序、交换和交换功能:

void quickSort(string array[], int left, int right)
{
      int I, J, pivot;
      char chI, chJ, chPivot;

      if(left<right)
      {
                    pivot=left;
                    I=left;
                    J=right;
                    while(I<J)
                    {
                               chI=IthChar(array[I], 0);
                               chJ=IthChar(array[J], 0);
                               chPivot=IthChar(array[I], 0);
                               while(chI<=chPivot&&I<right)
                               I++;
                               while(chJ>chPivot)
                               J--;
                               if(I<=J)
                               {
                                       swap(array, I, J);
                               }
                    }   
                    swapPivot(array, pivot, J);
                    quickSort(array, left, J-1);
                    quickSort(array, J+1, right); 
      }
}

void swap(string array[], int loc, int loc1) 
{
          int temp;

          temp=array[loc];
          array[loc]=array[loc1];
          array[loc1]=temp;
}     

void swapPivot(string array[], int pivot, int J)
{
          int temp;

          temp=array[pivot];
          array[pivot]=array[J];
          array[J]=temp;
}
void快速排序(字符串数组[],左整数,右整数)
{
inti,J,枢轴;
char chI、chJ、chPivot;

如果(左边的p>你应该写一个字符串比较函数(或重用你),那么,你肯定它是C而不是C++吗?问题是什么?这里唯一的问号是这个注释。注意,<代码> TEMP被声明为<代码> int <代码>,但是后来你分配了一个<代码>字符串< /代码>:[pivot];
您只需编写
std::sort(strVector.begin(),strVector.end())是的,在c语言中,问题是为什么它不打印或使用AdrianJandl中的strcmp,这就是我当时的想法,但是我有一个印象,由于奇怪的
IthChar
,OP在重新实现字符串。考虑到他正在将字符串分配给一个普通的
char
,我假设
IthChar
是一个不遵循命名约定的函数。@PaulFilch: