
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating a Set Object
|
659
// Remove all nodes below node 'Two'.
// Nodes 'Five' and 'Six' are removed.
topLevel.GetRoot( ).BreadthFirstSearch("Two").RemoveNode(0);
// Remove node 'Three' from the root node.
topLevel.GetRoot( ).RemoveNode(1);
See Also
See the “Queue<T> Class” and “IComparable Interface” topics in the MSDN
documentation.
11.8 Creating a Set Object
Problem
You need an object that contains a group of unordered objects. This object must be
able to be compared to other objects containing sets of data. In addition, the two
must be able to have the following actions performed on them:
• Union of the items contained by the two objects containing sets of data
• Intersection of the items contained by the two objects containing sets of data
• Difference of the items contained by the two objects containing sets of data
Solution
Create a Set<T> object, the code for which is shown in Example 11-17.
Example 11-17. Set class
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class Set<T> : IEnumerable<T>
{
private List<T> internalSet = new List<T>( );
public int Count
{
get {return (internalSet.Count);}
}
public T this[int index]
{
get
{
return (internalSet[index]);