Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to implement a Join function in C++

Status
Not open for further replies.

mikerez

Programmer
Jan 17, 2003
1
US
This is my first post on tek-tips. I appologize if this is not the correct forum for this question.

I am trying to implement a function that will execute a join of tables (implemented as arrays). I want this to work like a SQL join of two tables, but aginst arrays.

What I'm looking for is some sample logic that should be used to joing two arrays as if they were tables.

Any help would be appreciated.

Thanks!
 
I don't know if there's a 'clever' algorithm for this, but I'd proceed something like this:

1. Either sort your arrays in the sequence of the join condition (one or more fields) or if the records in the arrays are large or there's a lot of 'em, create new key-reference arrays and sort those instead.

2. Get the first key of each array and check for a match. Do whatever's needed if there is.

3. Get the next key of the array whose key was the lower of the two (or both if there was a match).

4. Check for a match

repeat 3 & 4 until one or the other array is exhausted.

Something like that, anyway...

HTH,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top