벡터를 함수에 대한 인수로 보내려고하는데 어떻게 작동하는지 알 수 없습니다. 여러 가지 방법을 시도했지만 모두 다른 오류 메시지를 표시합니다. 이 부분 만 작동하지 않기 때문에 코드의 일부만 포함합니다. (벡터 "random"은 0에서 200 사이의 임의의 값으로 채워지지만 정렬 됨)
코드 업데이트 :
#include <iostream>
#include <ctime>
#include <algorithm>
#include <vector>
using namespace std;
int binarySearch(int first, int last, int search4, vector<int>& random);
int main()
{
vector<int> random(100);
int search4, found;
int first = 0;
int last = 99;
found = binarySearch(first, last, search4, random);
system("pause");
return(0);
}
int binarySearch(int first, int last, int search4, vector<int>& random)
{
do
{
int mid = (first + last) / 2;
if (search4 > random[mid])
first = mid + 1;
else if (search4 < random[mid])
last = mid - 1;
else
return mid;
} while (first <= last);
return -(first + 1);
}