Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a series of Key value pairs. Each Key has 2 values. Values of Keys ma coincide.
Initially i start with Key1, ValueKey1, ValueKey2 are stored in a set.(Maybe Array).

Now for each consecutive Keyi, i check if Valuei, Valuei+1 are in the set. If any one of them is in the set, then join the set.

Else if both KeyValues are present in a set, discard that key .


How can i implement this thing using C++, i have very less idea, so i would suggest if possible a code snippet or a hint would be really helpful.
Posted
Comments
Sergey Alexandrovich Kryukov 5-Nov-11 20:51pm    
Not clear. Where is the union operation? How so: "If any one of them is in the set, then join the set"? If something is already in the set, why joining it?
Look, use precise mathematical notation, not your vague words.
--SA

1 solution

A hint? OK, I'll give a hint, but first, see my comment to the question and realize that your formulation of the problem is not clear.

Now, a hint: you simply need implementation of set-theory operation like union (disjunction). Simply implement it by definition of that operation.

Try it and show us your code if you face any problems; if you also explain where is your difficulty, we can probably help you.

—SA
 
Share this answer
 
Comments
RaisKazi 6-Nov-11 2:48am    
Agree. Hints are always better than ready made code-snippet. 5ed
Sergey Alexandrovich Kryukov 6-Nov-11 10:16am    
Thank you, Rais.
Well, in this case more advanced suggestions and even code fragment could be useful, but OP needs to provide more detail.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900