Quick help with descending order

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
im working with structures.
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-1; b++)
        for(int j=0; j<n+1;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 
        }
    }
Last edited on
n+1
that's to far, only go to n

didn't look at the algorithm, just at the for loops, your algorithm may be broken as well.
Last edited on
Topic archived. No new replies allowed.