Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CListBox sorting

Status
Not open for further replies.

we3royalee

Programmer
Dec 25, 2000
1
US
I am trying to sort the strings in a CListBox by a value in the middle of the string, so the supplied sort will not work. Here is an example of a string from the list box:
"1 bill/bob/bert 25.005 2". The values are tab separated. I need to sort in ascending order by the 25.005 value(let me call it time), so I have been parsing it out of the string and using atoi, then comparing the times of two of the strings, and moving the larger value to the end of the list. This means I have to sort several times to totally sort it. Any ideas on how to sort this list box would be greatly appreciated.

 
Hmm....don't know if this is any help, but I'm doing something similar...without all the string to integer conversion though. I don't know what type of sorting routine you are using, but a bubble sort routine works pretty good for me. It's a bit difficult to explain in this short of space, but I think it is a fairly fast routine...try looking it up and see if that would help you out. If you can't find anything else on it, I'll try and squeeze an explaination out.

Hope this helps.

Niky Williams
NTS Marketing
 
Sounds like a job for qsort(). It's been around a long time, is very fast AND it's built in!

Good luck
-pete
 
My guess would be that when u try to insert the data into the listbox, insert it into the sorted position i.e your insertion logic should compute the position. Thus u can insert the data before you build the string that u mentioned.

Sriks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top