DataSharp/Mathematics/SetHelper.cs
/// <summary>
/// Returns all the subsets of the input set except the empty set and the set itself in an enumerator.
/// </summary>
/// <typeparam name="T">The type of elements in the set.</typeparam>
/// <param name="set">A set that contains some elements.</param>
/// <returns>All the subsets of the input set except the empty set and the set itself in an enumerator.</returns>
Returns all the subsets of the input set except the empty set and the set itself in an enumerator.
Returns all the subsets of the input set except the empty set and the set itself in an enumerator .
public static IEnumerable<ISet<T>> GetAllSubsets<T>(ISet<T> set)
        {
            LinkedList<ISet<T>> subsets = new LinkedList<ISet<T>>();
            for (int i = 1; i < set.Count; i++)
            {
                foreach (ISet<T> s in GetSubsets(set, i))
                    subsets.AddLast(s);
            }
            return subsets;
        }
public static IEnumerable < ISet < T > > GetAllSubsets < T > ( ISet < T > set ) { LinkedList < ISet < T > > subsets = new LinkedList < ISet < T > > ( ) ; for ( int i = 1 ; i < set . Count ; i ++ ) { foreach ( ISet < T > s in GetSubsets ( set , i ) ) subsets . AddLast ( s ) ; } return subsets ; }
Returns all the subsets of the input set except the empty set and the set itself in an enumerator.
Returns all the subsets of the input set except the empty set and the set itself in an enumerator .
// Initialize an empty linked list to store all the subsets of the input set. // Generate all the subsets with i elements, where i = 1, 2, ..., set.Count - 1 // Get the subsets and add them to the LinkedList<ISet<T>>. // Return the subsets.
All the subsets of the input set except the empty set and the set itself in an enumerator.
All the subsets of the input set except the empty set and the set itself in an enumerator .
set
ISet<T>
A set that contains some elements.
A set that contains some elements .
typeparam
The type of elements in the set.
The type of elements in the set .