1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Which datastructure to use for set of sets

Discussion in 'C' started by tonyaim83, Jan 23, 2008.

  1. tonyaim83

    tonyaim83 New Member

    Joined:
    Jan 23, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. tonyaim83

    tonyaim83 New Member

    Joined:
    Jan 23, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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}}}
     
  3. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    Why did you decide that a set only ever has two elements (a pair)?
     
  4. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    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.
     

Share This Page