multiple occurrence issue

this is part of the program. i keep getting the same index position for numbers that occur more than once. i was wondering if the answer to my problem can be found in this part?

1
2
3
4
5
6
7
8
9
10
int function2(int arr[],int SIZE, int pos)
{
 for (int a=0;a<SIZE;a++)
 {
  if(arr[a]==pos)
  {
   return a;
  }
 }
}
There's nthing wrong here,, but what is pos ?
Last edited on
the values from another array. so what would i do so the second occurring number gives its actual index position instead of the first one?
How about this, check the where it is first, then check the next one before returning it
if(arr[a+1]==pos)
Last edited on
that didnt work, check what first?
Ah sorry I mean find the first ocurence of pos, then before return the index check another occurence of pos in the next position
how would i do that?
1
2
3
4
for(int i=0;I<size-1;i++){
    if(arr[i]==pos&&arr[i+1]==pos)
    return (i+1);
}


What your program do ? I'm affrad that I. Have wrong perception
it takes the values from one array and searches for their index position in another array(linear search algorithm). i got that down except for the part i mentioned above
Ooh I thought that you'll delete the double -.-)" or something

Sooo for ex
a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}
First step find 1 in arr, and it'll return 0
Then find 2 in array and it'll return 1 and 2 ?
^yes except it return 1 and 1 when it finds 2
In that case don't return anything before search trough the array, just save the index in some variable
how do i do this? any thoughts?
Topic archived. No new replies allowed.