Iterator/generator that returns all subsets for an N
element set.
More...
#include <subset.h>
template<int N>
class subset< N >
Iterator/generator that returns all subsets for an N
element set.
{ }
{ 0 }
{ 1 }
{ 0 , 1 }
{ 2 }
{ 0 , 2 }
{ 1 , 2 }
{ 0 , 1 , 2 }
*/
const bool *SS = iter.
next();
bool didOne = false;
std::cout << "{ ";
for (
int i=0; i<iter.
DIM(); ++i ) {
if ( SS[i] ) {
if ( didOne ) {
std::cout << " , ";
}
std::cout << i;
didOne = true;
}
}
std::cout << " }" << std::endl;
}
}}
- See Also
- http://compprog.wordpress.com/2007/10/10/generating-subsets/
Definition at line 21 of file subset.h.
Constructor. DIM() == N
Constructor. Set has
elements.
Definition at line 53 of file subset.h.
Destructor.
Definition at line 27 of file subset.h.
template<int N>
subset< N >::hasNext |
( |
| ) |
const |
|
inline |
Returns true
while there are more subsets to generate.
Definition at line 28 of file subset.h.
Generate next subset.
Definition at line 36 of file subset.h.
Returns the size of the complete set.
Definition at line 32 of file subset.h.
Marks which elements are in the current set.
Goes from 2^n
down to 0
.
Definition at line 23 of file subset.h.
The documentation for this class was generated from the following file: