나는 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)" ([email protected]@[email protected]) referenced in function "void __cdecl checkIfNumberIsMoreThenThreeTimes(int * const,int)" ([email protected]@[email protected])
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;
}
}
도와주세요! 사전에 감사 .... void checkIfNumberIsMoreThenThreeTimes(int arr[], int n)
에서
mergeSortP 이중 포인터를 원한다. 단일 포인터를 전달하려고합니다. –
@ user3328918 - 실례합니다. 내 병합을 사용하면 병합 유형을 사용하여 문제를 해결할 수 있습니다. 즉, 배열에서 숫자가 발생하는 횟수를 계산하고 색인을 나열 할 수 있습니까? 만약 당신이 정말로 C++을 배우고 있다면, 명백한 해결책은 std :: map를 사용하는 것입니다. SomeStruct는 발견 된 인덱스를 포함하는 수와 벡터를 포함하는 구조체입니다. 아마 5 ~ 6 줄, 10 줄까지 쓸 수 있습니다. –
PaulMcKenzie
@PaulMcKenzie에 동의합니다. 요즘 C++ 교육을 통과하는 것이 맞습니까? _Double_ 포인터? C++을 배우는 사람들이 _regular_ 포인터에 문제가 있습니까? – Chad