Thanks for your help. It work fine if col_data[10] is in below order
Code:
gg col_data[10]={{0,44},{0,46},{0,39},{1,25},{1,10},{2,46},{2,78},{2,55},{3,64},{3,79}};
I am sorry i provide the data into wrong order it should be like that
Code:
gg col_data[10]={{3,44},{3,46},{2,39},{2,25},{2,10},{1,46},{1,78},{0,55},{0,64},{0,79}};
In that case if i run the above code it shows me output as
Code:
ptr[0]:7
ptr[1]:0
ptr[2]:0
ptr[3]:0
As it find the first element in the last of array. How can i copup with it?
Originally Posted by
DRK
No, it won't continue.
i < 4 condition terminates loop when all 4 indexes are found.
Here's a new solution for you:
Code:
for (i = 0; i < 4; ++i)
{
ptr[i] = -1; // index not yet found
}
for (i = 0, j = 0; i < 4 && j < 10; ++j)
{
int id = col_data[j].id;
if (id < 4 && ptr[id] == -1)
{
ptr[id] = j;
++i;
}
}