In a binary search, with an even amount of numbers, will the algorithm choose the higher or lower middle number?
So if the array is:
15 18 18 21 26 31 36 38
Then will it start by looking at 21 or 26?
User Profile
Collapse
Profile Sidebar
Collapse
millman
Last Activity: Nov 10 '11, 05:21 PM
Joined: Oct 21 '11
Location: United Kingdom
-
A binary search with even amount of numbers
-
no problem thanks anyway alexis
And to solve the problem that when you enter an odd number into the running program it won't show the next ten alternate numbers. But i still need a code to loop back to the start. Anyway, this is the corrected program.
Code:#include <StdAfx.h> #pragma hdrstop #include <conio.h> #include <ctype.h> #include <iostream> //----------------------------------------------------------------------
-
Loop back to the start of a program?
Code:#include <StdAfx.h> #pragma hdrstop #include <conio.h> #include <ctype.h> #include <iostream> //---------------------------------------------------------------------- using namespace std; using std::cout; using std::endl; using std::cin; int main ( ) { int i; int x; std::cout << "\n
-
Don't worry, i worked it out myself but just incase anyone else has a similar problem you need two equals signs like this == in the if statement. Also if you use windows visual c++ you need this header file. #include <StdAfx.h>Leave a comment:
-
Error message 'non-lvalue in assignment', any suggestions?
Code:#pragma hdrstop #include <conio.h> #include <ctype.h> #include <iostream> #pragma argsused //------------------------------------------------------- using namespace std; int main ( ) { int i; int x; std::cout << "\nPlease enter an even number:"; cin >> x; if(x%2=1) std::cout <<
No activity results to display
Show More
Leave a comment: