1

我正在尝试使用插入排序按字母顺序对名称列表进行排序,为此我需要比较两个对象数组,但是当我使用标准字符串库函数compare时,编译器将其解释为我想访问我的数据成员类,实际上我想访问保存字符串的类的数据成员。

void Course::sortRow(int RowtoSort)
{
    int i, j;

    Student bucket; 

    for(i = 1; i < enrolled[RowtoSort];i++)
    {
        //assign bucket with temp value for swap
        bucket = Students[RowtoSort][i]; 

        for(j = i;
            (j > 0) && (Students[RowtoSort][j-1].compare(bucket)) < 0;
            j--) //how would I compare the two arrays of objects?
            {
                //assign j to element j-1 so now both j and j-1
                // are the same in the array
                Students[RowtoSort][j] = Students[RowtoSort][j-1]; 
            }

            //now j-1 value is at j and since j-- assign it
            // to bucket to place the proper value at j-1  
            Students[RowtoSort][j] = bucket;
        } // end outer loop
    }

我将如何将这两个对象Students[RowtoSort][i]与 Bucket 进行比较?

4

0 回答 0