|
-
December 9th, 2014, 10:12 PM
#1
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?
Code:
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;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|