条件遍历LinkedHashSet并构建所有可能的唯一组合?

时间:2018-04-12 15:25:22

标签: java data-structures

如何有条理地遍历链接的HashSet并获得结果

Given set A = {A, B, C};

Given Set B = {D, E, F}; <- Keeping this set unchanged 

按顺序迭代,

node A -> 
  if(! Some condition) {
      skip node A and Goto B;
  }else{
     {D, E, F,A}, {D, E, F, A,B}, {D,E,F,A,C}; 
  }
node B -> 
  if(! Some condition) {
        skip node B and Goto C;
  } else{
    {D, E, F,B}, {D, E, F,B,C}
  }
node C -> 
  if(! Some condition) {
        exit;
  }else{
      {D, E, F,C}
  }

结果就是,

   {D, E, F, A}
   {D, E, F, A, B}
   {D, E, F, A, C}
   {D, E, F, B}
   {D, E, F, B, C}
   {D, E, F, C}
   {D, E, F, A, B, C}

0 个答案:

没有答案