所以我尝试使用冒泡排序按姓氏排序名称。有问题的名称存储在结构中,结构在数组中。那么我如何为for循环中的每个实例拉出名称,并且只按姓氏组织?
struct Person{
string Name;
char Status;
double Income, Taxes, Net_Salary;
};
void B_sort(Person[], int size); //Prototype
Person Plist[MAX_SIZE];// in int main()
void B_sort(Person Plist[], int size) // Here is the main course{
Person Temp;
bool Swap;
string first, last;
do{
Swap = false;
size--;
for (int i = 0; i < size; i++)
{
int blankpos = Plist[i].Name.find(" ");
first = Plist[i].Name.substr(0, blankpos);
last = Plist[i].Name.substr(first, blankpos); //not even sure if this is right, I really don't how to even
if (Plist[i].Name > Plist[i + 1].Name){
Temp = Plist[i];
Plist[i] = Plist[i + 1];
Plist[i + 1] = Temp;
Swap = true;
}
}
}while (Swap);
};