CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Sorting question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

Sorting question
PostPosted: Wed Mar 07, 2007 11:28 pm     Reply with quote

Greetings,

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

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 11:24 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group