Hello, so i need quick help with putting stuff in order. i have a text file:
6
v k 250
m k 280
v p 240
m p 290
v s 63
m s 45
i need to to make this into descending order by numbers so it would look like this :
m p 290
m k 280
v k 250
v p 240
v s 63
m s 45
Here's what i came up with, but program crashes
1 2 3 4 5 6 7 8 9 10
for(int b=0; b<n; b++)
for(int j=0; j+1<n;j++)
{
if(A[j].kaina>A[b].kaina) // kaina == price
{
A[j].kaina = B[b].kaina;
A[j].lytis = B[b].lytis; // lytis == sex
A[j].tipas = B[b].tipas;; // tipas == type of the clothes
}
}
IT looks like you're trying a bubble sort. At lines 6-8, you probably need to swap A[j] and A[b] rather than copying A[b] to A[j]. Also the loop at line 2 should probably be for (int j=0; j < b; ++j)
Well assigning values to A from B seems wrong to start with. It looks like B is empty, unless there are some other "hidden" functions.
To sort your array of structures you can swap the entire structure at once, you don't need to swap all the individual elements of the structure, as stated by dhayden above.