Archived

This topic is now archived and is closed to further replies.

Zeke

Sorting

Recommended Posts

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

Share this post


Link to post
Share on other sites
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-

Share this post


Link to post
Share on other sites