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. Help with Array Sort

Help with Array Sort

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorialquestion
4 Posts 4 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.
  • L Offline
    L Offline
    Loli10
    wrote on last edited by
    #1

    Consider the following array, whose contents are NOT sorted: int Ids[10]={12,4,22,67,2,5,11,33,6,10}; If a binary search routine is written to search through this array, what will happen? For example, Will the program abort, since the array is not sorted? or will the binary search routine be successful, but inefficient? or Will the binary search fail? or ??? Loli10

    A T N 3 Replies Last reply
    0
    • L Loli10

      Consider the following array, whose contents are NOT sorted: int Ids[10]={12,4,22,67,2,5,11,33,6,10}; If a binary search routine is written to search through this array, what will happen? For example, Will the program abort, since the array is not sorted? or will the binary search routine be successful, but inefficient? or Will the binary search fail? or ??? Loli10

      A Offline
      A Offline
      Anders Molin
      wrote on last edited by
      #2

      The binary sort will fail. - Anders Money talks, but all mine ever says is "Goodbye!"

      1 Reply Last reply
      0
      • L Loli10

        Consider the following array, whose contents are NOT sorted: int Ids[10]={12,4,22,67,2,5,11,33,6,10}; If a binary search routine is written to search through this array, what will happen? For example, Will the program abort, since the array is not sorted? or will the binary search routine be successful, but inefficient? or Will the binary search fail? or ??? Loli10

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        Binary search on a non-sort list will yield a LOT of erronious "not found"s. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

        1 Reply Last reply
        0
        • L Loli10

          Consider the following array, whose contents are NOT sorted: int Ids[10]={12,4,22,67,2,5,11,33,6,10}; If a binary search routine is written to search through this array, what will happen? For example, Will the program abort, since the array is not sorted? or will the binary search routine be successful, but inefficient? or Will the binary search fail? or ??? Loli10

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Sort it first. Binary search expects a sorted array. It won't crash your program, but you will get wrong results for your search if the array is unsorted. Nish It's seven o'clock On the dot I'm in my drop top Cruisin' the streets - Oh yeah I got a real pretty, pretty little thing that's waiting for me

          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