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. STL list vs multi set

STL list vs multi set

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiotutoriallearning
5 Posts 3 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
    minkowski
    wrote on last edited by
    #1

    Hi, I was wondering if you could give me an example of when you would want to store objects in a list and when would you want to store them in a multi set. The multi set of course having the ability to store multiple values of the same object. Thanks

    7 S 2 Replies Last reply
    0
    • M minkowski

      Hi, I was wondering if you could give me an example of when you would want to store objects in a list and when would you want to store them in a multi set. The multi set of course having the ability to store multiple values of the same object. Thanks

      7 Offline
      7 Offline
      73Zeppelin
      wrote on last edited by
      #2

      You could use a multi set to store the factors of a prime number, say, 120: {2, 2, 2, 3, 5} Using a list this would be {2,3,5} if you just wanted to identify the factors themselves. Using the multi set, you could recontruct the prime (by multiplication of the contents of the multi set). The list would just give you the factors.


      M 1 Reply Last reply
      0
      • 7 73Zeppelin

        You could use a multi set to store the factors of a prime number, say, 120: {2, 2, 2, 3, 5} Using a list this would be {2,3,5} if you just wanted to identify the factors themselves. Using the multi set, you could recontruct the prime (by multiplication of the contents of the multi set). The list would just give you the factors.


        M Offline
        M Offline
        minkowski
        wrote on last edited by
        #3

        Hey thanks for your input. I thought Lists can store duplicates ? So it could store {2,2,2,3,5} ?

        7 1 Reply Last reply
        0
        • M minkowski

          Hey thanks for your input. I thought Lists can store duplicates ? So it could store {2,2,2,3,5} ?

          7 Offline
          7 Offline
          73Zeppelin
          wrote on last edited by
          #4

          I think the difference is that multiple identical elements in a multi set can serve as their own sort keys, so the keys are not unique.


          1 Reply Last reply
          0
          • M minkowski

            Hi, I was wondering if you could give me an example of when you would want to store objects in a list and when would you want to store them in a multi set. The multi set of course having the ability to store multiple values of the same object. Thanks

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #5

            List gives you fast insertion (O(1)), potentially slow lookup (O(n)). Multiset gives you sorted insertion, and reasonably fast lookup (both O(log n)).

            But who is the king of all of these folks?

            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