It depends on if you want to pass the vector
as a reference or as a pointer (I am disregarding the option of passing it by value as clearly undesirable).
As a reference:
int binarySearch(int first, int last, int search4, vector<int>& random);
vector<int> random(100);
// ...
found = binarySearch(first, last, search4, random);
As a pointer:
int binarySearch(int first, int last, int search4, vector<int>* random);
vector<int> random(100);
// ...
found = binarySearch(first, last, search4, &random);
Inside binarySearch
, you will need to use .
or ->
to access the members of random
correspondingly.
Issues with your current code
binarySearch
expects a vector<int>*
, but you pass in a vector<int>
(missing a &
before random
)binarySearch
before using it (for example, random[mid]
should be (*random)[mid]
using namespace std;
after the <include>
sfirst
and last
are wrong (should be 0 and 99 instead of random[0]
and random[99]