AnsweredAssumed Answered

Sort an array - find the best way!

Question asked by LuigiDiPalo on Dec 4, 2013
Latest reply on Dec 18, 2013 by gpan

Hi,

I'm using adsp-bf609 ez-board. In my code i've to sort an array of 1024 elements. This is a monodimensional array of float POINT_Z[1024].

I've also the array POINT_Y[1024]. The index are correlated and indicate a couple of points. Same index, same point.

How can I order this array by Z in an efficient way? I'm using a selection sort algorithm but i need 7 to 9 ms for this.

I need a best solution to sort these vectors in less than 3 ms.

Any suggestions?

This is the code i'm using:

 

for(PUNTI = 0; PUNTI<1024;PUNTI++)
                                 {
                                   posmax = PUNTI;
                                   for (j = (PUNTI + 1); j<1024; j++)
                                         {
                                           if (PUNTI_Z[j] > PUNTI_Z[posmax])
                                           {
                                             posmax = j;
                                           }
                                         }
                                     aus = PUNTI_Z[PUNTI];
                                     ausy = PUNTI_Y[PUNTI];
                                     PUNTI_Z[PUNTI] = PUNTI_Z[posmax];
                                     PUNTI_Y[1, PUNTI] = PUNTI_Y[posmax];
                  PUNTI_Z[posmax] = aus;
                                     PUNTI_Y[posmax] = ausy;
                               }

Outcomes