index position in array Issue

my program takes the values from one array and searches for their index position in another array(linear search algorithm).
this is an example of the issue im having(its not part of the actual code below)
a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}
if it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2. any thoughts on how to fix this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for (int q=0; q=size2;q++)
{
  int rs=secfunc(array1;size1;array2[q])
  if(rs>=0)
  {
    cout<<rs << "\n";
  }
}

return 0;

int secfunc(int arr[],int SIZE, int values)
for (int a=0;a<SIZE;a++)
 {
  if(arr[a]==values)
  {
   return a;
  }
 }
return -1;
}
When you find a match, do not stop searching. Or, if you do stop searching, you need to start searching again from after where you left off.
Kind of confused. How do i go about in doing that?
Say you're looking for programming books at the library. Do you exit the library completely after you find the first book, or do you keep looking for more books without leaving the library?
so once it finds the first match, how can i make it find the other matches if it has one?
Last edited on
I didn't write your code, only you know that.

To be honest, I can't tell what part of your posted code is the linear search.
Topic archived. No new replies allowed.