I have need to sort some data and need your input.
I've been using my own home-brewed code to sort a bit of data. I have declared variables:
int16 time[60];
int8 best[60];
The data in time[] needs to remain intact and unsorted. The variable, best[] is used to track which time[] variable has the lowest value. If time[25] has the lowest value then best[0] will have the value of 25. If time[2] is the next lowest then best[1] will have the value of 2 and so on. I've looked at qsort() but I'm not sure if this will end up sorting the original data.
So far I've only needed to sort the lowest six places (best[] used to only have six places) but now I need to sort the entire array. Time[] could have values inserted into the first three locations and up to time[60] and I need to sort up to the last location that has been saved. Another variable tracks how many values have been saved.
I know this is a good place to ask since there are many intelligent minds that frequent here.
Ronald
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
Posted: Thu Mar 08, 2007 11:24 am
Maybe you could do this. Identify how many values in the time[] array are less than time[x].
If y are less then best[y] =x;
etc...
The only problem is what you do to handle time[] values that are equal.
This would be 60 loops with 59 compares. I think this would compile to be minimal amount of code but run time could probably be improved.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum