given struct

s={int A; int B};

what is most logical and fastest way to find the B element given A in this array or vice versa?.

s table1[]={{1,2},{3,4},{5,6},..};  

Recommended Answers

All 2 Replies

This is a very much artificial set of data elements, in that both the A and the B parts are in sorted order in your example. If that is indeed the case, then you can use a binary search on the structures to most quickly find either the A or B keys.

no, the order was accidental.
s={int A; int B};

It is like:

s table1[]={{10,2},{3,4},{5,1},{9,0}..};   etc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.