还有题目要请教!!!
下面是一个快速排序函数:
MAXCHARS = 31
---------------------------------------------------------
void quicksort(char data[][MAXCHARS], int low, int high)
{
int i,j;
char *pivot = (char*)malloc( MAXCHARS * sizeof( char ));
printf( "pivot : %s , %d \n " , pivot, strlen(pivot) ); //这里竟然不是31,而是输出35!为什么?
if( low < high )
{
strcpy( pivot, data[low] );
i=low;
j=high;
while( i < j )
{
while( i < j && strncmp(data[j], pivot, 13 ) )
{
j--;
}
if( i < j )
{
strcpy(data[i++], data[j]);
}
while( i < j && strncmp( pivot, data[i], 13 ) )
{
i++;
}
if( i < j )
{
strcpy( data[j--], data[i]);
}
}
strcpy( data[i], pivot);
quicksort( data, low, i-1 );
quicksort( data, i+1, high);
}
}
调用处:
char buffer[MAXROWS][MAXCHARS];
quicksort( buffer, 0, 10) ;
-------------------------------------
结果是运行后,正常,但没起排序效果!!问题出在什么地方呢?