Advertisement

Sorting

Started by June 13, 2001 09:00 AM
1 comment, last by Zeke 23 years, 8 months ago
I have an array of CStrings with elements like: C:\WINDOWS\Desktop\TempBMs\1Lord_00_00.bmp C:\WINDOWS\Desktop\TempBMs\1Lord_00_01.bmp C:\WINDOWS\Desktop\TempBMs\1Lord_01_00.bmp C:\WINDOWS\Desktop\TempBMs\Voltemand_00_00.bmp C:\WINDOWS\Desktop\TempBMs\Voltemand_00_01.bmp C:\WINDOWS\Desktop\TempBMs\Voltemand_01_00.bmp C:\My Documents\Hamlet\Content\Hamlet.asc etc (might have up to and beyond 1000 elements) I need to sort this array to give me the list in alphabetical order. However most of the array is irrelevent I just want the list to have alphabetical order from the filename. So after sorting the list above would be C:\WINDOWS\Desktop\TempBMs\1Lord_00_00.bmp C:\WINDOWS\Desktop\TempBMs\1Lord_00_01.bmp C:\WINDOWS\Desktop\TempBMs\1Lord_01_00.bmp C:\My Documents\Hamlet\Content\Hamlet.asc C:\WINDOWS\Desktop\TempBMs\Voltemand_00_00.bmp C:\WINDOWS\Desktop\TempBMs\Voltemand_00_01.bmp C:\WINDOWS\Desktop\TempBMs\Voltemand_01_00.bmp I can sort the list to give me complete alphabetical order (i.e. the whole string, so the hamlet.asc string would come first in the example) Or i can get the way I want it done but by doing the foloowing code:


CString* NameOnly=new CString[NumItems];
	UniFuncs Functions;
	for (x=0;x 
So i am extracting the filename from the string, sorting that, and then comparing each element of both strings, to each other. This works but obviously with a lot or elements this is going to be soooo slow.

Can anyone give me some pointers or help on how i can do this?

Thanks for your time and any help you can offer 
    
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
I would suggest that you make a struct with the filename and the filepath then you sort the structs by filename, and you can then concatenate the strings again.

  typedef struct{  CString m_csFilename;  CString m_csFilepath;} SFILE;  


now that you are using qsort you can overwrite the compare function to take your struct as input and compare only by the m_csFilename.

Hope this can help you.

-Vissing-
-Vissing-
Advertisement
Thanks very much vissing, I really appreciate it.
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face

This topic is closed to new replies.

Advertisement