c++ - How to pass a vector to a function? -


I am trying to send a vector as an argument for the function and I can not understand that it How it works Tried a bunch of different methods but they all give different error messages. I only include part of the code because it is the only part that does not work. (Vector is full of "random" random, but sorted, values ​​between 0 and 200)

The code has been updated:

  #include & Lt; Iostream & gt; # Include & lt; Ctime & gt; # Include & lt; Algorithm & gt; # Include & lt; Vector & gt; using namespace std; Int binarySearch (int first, int final, int search4, vector & lt; int & gt; and random); Int main () {Vector & lt; Int & gt; Random (100); Int search4, found; Int first = 0; Int final = 99; Found = binary search (first, last, search4, random); System ("pause"); Return (0); } Int binarySearch (int first, int last, int search4, vector & lt; int & gt; and random) {do {int mid = (first + last) / 2; If (Search4> Random [Middle]) First = Middle + 1; And if (search 4th lieutenant; random [middle]) final = mid-1; And return again; } While (first & lt; = final); Return - (first + 1); }    

It depends on whether you vector

As a reference:

  int binarySearch (int first, int difference, int search 4, vector & lieutenant; int and end); Of vector & lt; Int & gt; Random (100); // ... found = binary search (first, last, search4, random);   

As an indicator:

  int binarySearch (int first, int last, int search4, vector & lt; int & gt; * random) ; Of vector & lt; Int & gt; Random (100); // ... found = binary search (first, last, search 4, and random);   

inside binary search , you . or - & gt; will be required to use random accordingly.

Issues with your current code

  1. Binary search code> vector < Int & gt; * , but you can enter a vector & lt; Int & gt; (missing random before & nbsp; )
  2. Before you use it the pointer (within the reference) binary Search should not be visible within (for example, must be random [middle] (* random) [
  3. < / Li>
  4. You ago and Assign to previous (instead of 0 and 99 random [0] and random [99] < / Div>

Comments