對於我的編程類的賦值,出現此錯誤: 錯誤1錯誤C2664:'binarySearch':無法將參數1從'int'轉換爲'INT []' 行34無法將參數1從'int'轉換爲'int []'
#include<iostream>
using namespace std;
int selectionSort(int[], int);
int binarySearch(int[], int, int);
int sorted;
int main()
{
int size;
int i;
int desirednum;
cout << "How many values do you want to enter?";
cin >> size;
int* userarray = 0;
userarray = new int[size];
for (i = 0; i < size; i++)
{
cout << "Enter a value: ";
cin >> userarray[i];
}
int sorted = selectionSort(userarray, size);//calls the selection sort function
cout << "What value are you looking for: ";//asks what value they are searching for
cin >> desirednum;
int location = binarySearch(sorted, size, desirednum);
delete[] userarray;
return 0;
}
int selectionSort(int numbers[], int size)
{
int i, j, min, minidx, temp, desirednum, sorted = 0;
cout << "What value are you looking for: ";
cin >> desirednum;
for (i = 0; i < (size - 1); i++)
{
min = numbers[i];
minidx = i;
for (j = i + 1; j < size; j++)
{
if (numbers[j] < min)
{
min = numbers[j];
minidx = j;
}
}
if (min < numbers[i])
{
temp = numbers[i];
numbers[i] = min;
numbers[minidx] = temp;
sorted++;
}
}
return sorted;
}
int binarySearch(int& user_array, int amount, int value)
{
int left, right;
int* middle;
left = 0;
right = amount - 1;
while (left <= right)
{
middle = (int*)((left + right)/2);
if (value == user_array[middle])
{
return *middle;
}
}
}
O.k.所以我已經將大小的變量數量轉換出來了。但是,如何修正聲明聲明,我拿出了符號符號但仍然不起作用。 – AaronBeta
@AaronBeta您需要與'binarySearch'中的聲明具有相同的定義,即用int int binarySearch(int user_array [],int amount,int value)替換int binarySearch(int&user_array,int amount,int value) ' – vsoftco
@AaronBeta,查看更新。 – Kat