Beginner needs help with sorting objects in a CTypedPtrArray
-
Hello, I need a fast algorithm to sort a CTypedPtrArray, that is, the pointers it contains. Here is roughly the class which is stored in the Array. It's called CClient: class CClient{ public: CClient(); ~CClient(); ULONG GetID(){return m_ID;}; CString GetName() {return m_Name;}; private: CString m_Name; ULONG m_ID; } Now in my code I attach to a given datasource (which contains quite a large amount of data) and start adding new CClients to the array. I would like to know what is the most effective way to insert each new CClient pointer so, that the items in the array are sorted descending by the m_ID member variable of the CClient class. Thank you for your time.
-
Hello, I need a fast algorithm to sort a CTypedPtrArray, that is, the pointers it contains. Here is roughly the class which is stored in the Array. It's called CClient: class CClient{ public: CClient(); ~CClient(); ULONG GetID(){return m_ID;}; CString GetName() {return m_Name;}; private: CString m_Name; ULONG m_ID; } Now in my code I attach to a given datasource (which contains quite a large amount of data) and start adding new CClients to the array. I would like to know what is the most effective way to insert each new CClient pointer so, that the items in the array are sorted descending by the m_ID member variable of the CClient class. Thank you for your time.
Hi, This won't answer your question but why don't you just use the STL. The STL has some very efficient sorting algorithms that I think you will find useful. If you don't know STL, I think you can get up to speed in just a few hours. If I had to do anything like this I would prefer the STL over the MFC collections. sayed