У меня есть проект в c++ -i получить массив, и мне нужно создать программу, которая будет печатать только числа, которые появляются более чем в 3 раза + их индекс. например, для массива 6,4,4,5,2,4,4,3,5,5 - он будет печатать: 4: 1,2,5,6 5: 3,8,9
и самое главное - оно должно быть не более O (n * log n).
sooo.... для проблемы...
это ошибка, которую я продолжаю получать:
1>HW - 2.obj : error LNK2019: unresolved external symbol "void __cdecl mergeSortP(int * const,int)" (?mergeSortP@@YAXQAHH@Z) referenced in function "void __cdecl checkIfNumberIsMoreThenThreeTimes(int * const,int)" (?checkIfNumberIsMoreThenThreeTimes@@YAXQAHH@Z)
1>C:\documents\visual studio 2012\Projects\HW - 2\Debug\HW - 2.exe : fatal error LNK1120: 1 unresolved externals
и это код:
void checkIfNumberIsMoreThenThreeTimes(int arr[], int n)
{
int **p;
p = copyToPointersArr(arr, n);
mergeSortP(*p, n);
output( arr, p, n);
}
//
int** copyToPointersArr(int *arr, int n)
{
int **pointers;
for (int i=0; i<n; i++)
*pointers[i]=arr[i];
return pointers;
}
//
void merge(int **a1, int **a2, int size1, int size2, int **res)
{
int ind1, ind2, ind;
ind1=ind2=ind=0;
while (ind1<size1 && ind2<size2)
{
if (*a1[ind1]<=*a2[ind2])
{
res[ind]=a1[ind1];
ind1++;
}
else
{
res[ind]=a2[ind2];
ind2++;
}
ind++;
}
while (ind1<size1)
{
res[ind]=a1[ind1];
ind1++;
ind++;
}
while (ind2<size2)
{
res[ind]=a2[ind2];
ind2++;
ind++;
}
}
//
void mergeSortP(int **a, int size)
{
int i;
int **temp=NULL;
if (size==1)
return;
else
{
mergeSortP(a, size/2);
mergeSortP(a+(size/2), size-(size/2));
temp = new int* [size];
merge(a, a+(size/2), size/2 , size-(size/2), temp);
for (i = 0; i < size; i++)
a[i] = temp[i];
delete []temp;
temp=NULL;
}
}
//
void output(int arr[], int **ptr,int size)
{
int i, j, count=0;
for (i = 0; i < size-1; i++)
{
if(*ptr[i]==*ptr[i+1])
count++;
else if (count>=2)
{
cout << *ptr[i] << ": ";
for (j = count; j >= 0; j--)
cout << (ptr[i-j]-arr) << ", ";
count=0;
}
else
count=0;
}
}
пожалуйста помоги!!! заранее спасибо....
Следующие могут помочь: https://ideone.com/oiAzTh
void displayFrequentNumber(const std::vector<int>& input)
{
std::vector<std::pair<int, std::size_t>> v;
for (std::size_t i = 0; i != input.size(); ++i) {
v.push_back({input[i], i});
}
std::sort(begin(v), end(v));
for (auto it = begin(v); it != end(v); ) {
auto next = find_if(it, end(v),
[it](const std::pair<int, std::size_t>& rhs)
{return it->first != rhs.first;});
if (next - it >= 3) {
std::cout << it->first << ":";
for (; it != next; ++it) {
std::cout << " " << it->second;
}
std::cout << std::endl;
}
it = next;
}
}
В void checkIfNumberIsMoreThenThreeTimes(int arr[], int n)
, у вас есть
int **p;
а также
mergeSortP(*p, n);
Итак, первый аргумент mergeSortP
имеет тип int*
.
Однако у вас есть только функция
void mergeSortP(int **a, int size)
поэтому компоновщик жалуется, потому что не может его найти. Возможно, вы хотели позвонить
mergeSortP(p, n);
вместо?