Array of sets of sets

Hello,

I have created an array of sets as follows:
set<int> A[2];
and wrote some code to access it.

Now, I want to create an array of sets of sets. i.e. something to store
A = [{[1],[3]} {[1],[3,4]} where A is an array of two set elements and the second set element also contains a set [3,4] within it.

I tried:
set<set<int>> A[2];
the difinition was compiled. However, I don't know how to access this data structure.

Any ideas of how to implement an array of sets of sets?

Thanks in advance...
I've never used sets, but I'm guessing this was the old way:
-Get your set through the array by index.
-Find your int by Key.

Now, add another layer of searching:
-Get your outer set through the array by index.
-Find the inner set you need by Key.
-Find the int by Key.
hi,

look at the reference for set, everything is explained (constructors, insertion and acessors)
http://www.cplusplus.com/reference/stl/set/

create each embedded set first then insert them in the nested structure.

iesomething like :
1
2
3
4
5
6
7
8
9
  
  set<int> set1_1, set1_2;
  set1_1.insert(1);
  set1_2.insert(3);
  set< set<int> > a1;
  a1.insert(set1_1);
  a1.insert(set1_2);
  A[0] = a1;
//same for the A[1] 


I suppose it should work, but it may not be very optimal, nor very human readable
Hi,

Thank you very much for the replies...
I have managed to create the data structure as what you said:
set<int> s1, s2;
s1.insert(1);
s2.insert(2);

set<set<int>> A[4];
A[0].insert(s1);
A[0].insert(s2);

Now A[0] contains two sets S1 and s2 exactly as what I want.
The problem is that I couldnt figure out how to write code to access them. I tried to use an iterator but didn't work. For example, how would I display the content of A[0].
Topic archived. No new replies allowed.