+ 4
How to arrange names in aplhabatical order in c++ ???
I am making a structure of food items and I want to know the code to how we can sort them alphabetically
1 Réponse
+ 6
string food1 = "", food2 = "";
for(int i = 0; i< length;i++)
{
food1 = food[i].name;
for(int j = i+1; j< length;j++)
{
food2 = food[j].name;
if(food1[i] > food2[j])
{
temp = food1[i];
food1[i] = food2[j];
food2[j] = temp;
}
}
}