This algorithms here is to find the common elements in two arrays.
(这里的算法是找到两个数组中的公共元素。)
Everything seems okay until I enter (一切顺利,直到我进入)
a[]={4,3,4,2}
b[]={4,1}
The output should be
(输出应为)
key[]={4}
Instead, it gives:
(相反,它给出:)
key[]={4,4}
How can I fix it?
(我该如何解决?)
int seqSearch(int arr[], int size, int key) {
for (int i = 0; i < size; i++)
if (arr[i] == key)
return i;
return 0;
}
void findDup(int a[], int b[], int& size1, int& size2, int key[], int& sizekey)
{
for (int i = 0; i < size1; i++)
for (int j = 0; j < size2; j++)
if (a[i] == b[j])
if (seqSearch(key, sizekey, a[i]) == 0)
{
key[sizekey] = a[i];
sizekey++;
}
}
int main() {
int a[max], b[max], key[100], size1, size2, sizekey=0;
findDup(a, b, size1, size2, key, sizekey);
}
ask by Phineas translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…