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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sorting algorithm

Sorting algorithm

Scheduled Pinned Locked Moved C / C++ / MFC
algorithms
5 Posts 5 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.
  • B Offline
    B Offline
    brucewayn
    wrote on last edited by
    #1

    I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance

    Q S CPalliniC S 4 Replies Last reply
    0
    • B brucewayn

      I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance

      Q Offline
      Q Offline
      quixqx
      wrote on last edited by
      #2

      find out how value_compare(), it will compare the values that way you will know which key comes first

      1 Reply Last reply
      0
      • B brucewayn

        I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance

        S Offline
        S Offline
        Swapnil Shah
        wrote on last edited by
        #3

        u can use STL <algorithm> http://msdn.microsoft.com/en-us/library/ecdecxh1(VS.80).aspx[^]

        1 Reply Last reply
        0
        • B brucewayn

          I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          You may try to implement yourself a simple sorting algorithm, like, for instance [^], it maybe an interesting experience. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • B brucewayn

            I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            If you used this:

            std::map<MarkType, NameType> marksAndStudents;

            (where MarkType is the type you use for a students marks and NameType is the type you use for a students name, then *rbegin() points at the student with the highest mark - try this:

            std::map<int, std::string> s;
            s.insert(std::make_pair(10, "10"));
            s.insert(std::make_pair(20, "20"));
            s.insert(std::make_pair(30, "30"));
            s.insert(std::make_pair(40, "40"));
            s.insert(std::make_pair(50, "50"));
            s.insert(std::make_pair(60, "60"));
            s.insert(std::make_pair(70, "70"));
            s.insert(std::make_pair(80, "80"));
            s.insert(std::make_pair(90, "90"));
            s.insert(std::make_pair(100, "100"));
            s.insert(std::make_pair(110, "110"));
            s.insert(std::make_pair(120, "120"));

            std::map<int, std::string>::const_reverse_iterator it = s.rbegin();
            for (int i=0;i<10;++i)
            {
            std::cout << it->second << std::endl;++it;
            }

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            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