// <summary> /// To do union of the two set. /// </summary> public IntegerSet Union(object obj) { IntegerSet tempSet = new IntegerSet(); for (int i = 0; i < this.set.Length; i++) { if (this.set[i] == true || (obj as IntegerSet).set[i] == true) { tempSet.set[i] = true; } } return(tempSet); }
// <summary> /// To do intersection of the two set. /// </summary> public IntegerSet Intersection(object obj) { IntegerSet tempSet = new IntegerSet(); for (int i = 0; i < this.set.Length; i++) { if (this.set[i] == true && (obj as IntegerSet).set[i] == true) { tempSet.set[i] = true; } else { tempSet.set[i] = false; } } return(tempSet); }
} // end Main // creates a new set by reading numbers from the user public static IntegerSet InputSet() { IntegerSet temp = new IntegerSet(); Console.Write("Enter number (-1 to end): "); int number = Convert.ToInt32(Console.ReadLine()); while (number != -1) { temp.InsertElement(number); Console.Write("Enter number (-1 to end): "); number = Convert.ToInt32(Console.ReadLine()); } // end while return(temp); }