Can you explain why i need to set the Min and Max to the value of the first array? |
If you set
Min
to some other value, then there might be a value that is less than that, so that value won't be set to
Min
. You could set
Min
to be the largest value that it's type can hold, but it's easier to just set it to the first value in the array.
What kind of search algorithm is this?
|
Not sure that it has any particular name.
Make sure you have your braces lining up: the one on line 15 should be in the same column as the brace on line 6, likewise with the brace on line 14 should line up with the one on line 8.
Also, it is very good practice to use braces - even where there is 1 line of code, as in lines 10 and 13. This will save you one day when you add some more code after line 10.
You should be able to set your IDE to do these things automatically. Even if you import some code that is badly formatted, your IDE can indent it properly for you. If you set your tabs to be 4 spaces, instead of an actual tab char - then it will display better on this site. Tabs are converted to 8 spaces here. Lines 10 & 13 should be indented more than the if statements. This stuff is important - it aids understanding & can help prevent errors.
While we are at it, don't have
using namespace std;
- there is plenty written on the web about why it is bad - Google it. Instead prefix each std thing with
std::
as in
std::cout
,
std::cin
,
std::endl
,
std::string
,
std::vector
etc.
It might seem to be a pain, but you can see that all the expert coders on this site do it.
Also,
conio.h
is not standard C++, so don't use it. You can
std::cin
a dummy variable if you want to keep your window open at the end. If you want to move the cursor around and do colours, have a look at ncurses.