選択ソートとポインターを使用して構造体の配列をソートしようとしていますが、問題が発生しています。
配列を出力して名前が並べ替えられているかどうかを確認しようとすると、最初の位置にある名前(並べ替えられていない)を除いて、すべての名前が並べ替えられます。
/*
all is the unordered array of struct; pLast is pointer to the last struct in array.
*/
void sortArray(CASE* all, CASE* pLast)
{
CASE* current;
CASE* walker;
CASE* smallest;
CASE temp;
for(current = all; current < pLast; current++)
{
smallest = current;
for (walker = current + 1; walker <= pLast; walker++)
{
if(strcmp(walker->name, smallest->name) < 0 )
smallest = walker;
}
temp = *current;
*current = *smallest;
*smallest = temp;
}
for(walker = all; walker <= pLast; walker++)
{
printf("%s\n", walker->name);
}
return;
}
任意のヒント?
ありがとう
編集:名前を印刷できるが完全にはソートされないメジャーリビジョン