Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Which datastructure to use for set of sets (http://www.go4expert.com/forums/datastructure-set-sets-t8420/)

tonyaim83 23Jan2008 13:33

Which datastructure to use for set of sets
 
What i want is to first store the given input as follows :-
{{{A,B},{B,C},{C,D}},{{A,C},{C,E},{E,F},{F,P}}}
and then make a check if the pair is present in particular subset of a set.
For e.g if the user can give index 0 and pair {B,C} we need to search the first index value i.e {{A,B},{B,C},{C,D}} and return true or false based on its presence. What data structure i should use. I tried vector but not helping me
Kindly help

tonyaim83 23Jan2008 16:02

Re: Which datastructure to use for set of sets
 
My current implementation look like
Code:


struct ElementPair         
{
 string First_element;
 string Second_element;
};

struct Element_set
{
 vector<ElementPair> ElementPairs;
};

void makeSet(string str1,string str2)
{
  ...
.... ..
....
 vector<Element_set > Pathset;

Now i need to assign str1 to First_element and str2 to Second_element so that my final stored data look like {{{A,B},{B,C},{C,D}},{{D,E},{E,F}}}

Salem 24Jan2008 00:50

Re: Which datastructure to use for set of sets
 
Why did you decide that a set only ever has two elements (a pair)?

oogabooga 24Jan2008 11:24

Re: Which datastructure to use for set of sets
 
Quote:

Originally Posted by tonyaim83
{{{A,B},{B,C},{C,D}},{{A,C},{C,E},{E,F},{F,P}}}
if the user can give index 0 and pair {B,C} we need to search the first index value i.e {{A,B},{B,C},{C,D}} and return true or false based on its presence. What data structure i should use.

Code:

    0    1    2    3
0 (a,b),(b,c),(c,d)
1 (a,c),(c,e),(e,f),(f,g)
2 (a,b),(a,c),(b,d)

Your data structure seems to be a ragged two-dimensional array of pairs.
Depending on what you want to do with it, perhaps a vector of sets of pairs.
If your base elements are just single characters you could use chars instead
of strings.


All times are GMT +5.5. The time now is 21:56.