struct command
{
char name[20];
int amount;
};
int main()
{
command n[10];
// Im sorting array in ascending order by the amount here
int temp;
for(int i=0; i<10; i++)
{
for(int j=0; j<10-1; j++)
{
if(n[j].amount>n[j+1].amount)
{
temp=n[j].amount;
n[j].amount=n[j+1].amount;
n[j+1].amount=temp;
}
}
}
}
Problem is, this code sorts out only n[].amount
, but I need to sort out name together with it. For example:
n[1].name="fff", n[1].amount=4, n[2].name="ggg", n[2].amount=1
and after sorting them out in ascending order it should be like this:
n[1].amount=1, n[1].name="ggg", n[2].amount=4, n[2].name="fff"
but my code only sorts out n[].amount. Sorry for the poor explanation, I'm really new to programming