Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Beginner needs help with sorting objects in a CTypedPtrArray

Beginner needs help with sorting objects in a CTypedPtrArray

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsdata-structureshelpquestionlearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matthias 0
    wrote on last edited by
    #1

    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.

    U 1 Reply Last reply
    0
    • M Matthias 0

      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.

      U Offline
      U Offline
      User 4315
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups