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. standard search algorithm

standard search algorithm

Scheduled Pinned Locked Moved C / C++ / MFC
4 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.
  • N Offline
    N Offline
    Nick Blumhardt
    wrote on last edited by
    #1

    Hey guys, What I need is a standard library algorithm to find an element in an ordered vector... binary_search would be fine if it returned an iterator--? Hope this isn't a dumb question, but all the suitable looking algorithms I found took linear time- surely what I need is in there, but where do I look? Thanks, nick

    L M 2 Replies Last reply
    0
    • N Nick Blumhardt

      Hey guys, What I need is a standard library algorithm to find an element in an ordered vector... binary_search would be fine if it returned an iterator--? Hope this isn't a dumb question, but all the suitable looking algorithms I found took linear time- surely what I need is in there, but where do I look? Thanks, nick

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      look at bsearch in < stdlib.h > Mh2!

      1 Reply Last reply
      0
      • N Nick Blumhardt

        Hey guys, What I need is a standard library algorithm to find an element in an ordered vector... binary_search would be fine if it returned an iterator--? Hope this isn't a dumb question, but all the suitable looking algorithms I found took linear time- surely what I need is in there, but where do I look? Thanks, nick

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

        ForwardIterator lower_bound(ForwardIterator beg, ForwardIterator end, const T& value)

        returns the position of the first element greater than or equal to value. There's also a version that takes a binary comparision predicate. It's logarithmic time for random access iterators.

        N 1 Reply Last reply
        0
        • M markkuk

          ForwardIterator lower_bound(ForwardIterator beg, ForwardIterator end, const T& value)

          returns the position of the first element greater than or equal to value. There's also a version that takes a binary comparision predicate. It's logarithmic time for random access iterators.

          N Offline
          N Offline
          Nick Blumhardt
          wrote on last edited by
          #4

          thanks a heap dude :rose:

          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