public static String getPowerSet(ArraySet e) { int n = Convert.ToInt32(Math.Pow(2, e.SIZE)); String result = "{{"; for (int count = 0; count < n; count++) { result += "{"; char[] binary = ToBinary(count).ToCharArray(); Array.Reverse(binary); char[] newArray = new char[e.SIZE]; for (int i = 0; i < binary.Length; i++) { newArray[i] = binary[i]; } while (newArray.Length < e.SIZE) { newArray[n - newArray.Length] = '0'; } Array.Reverse(newArray); for (int j = 0; j < newArray.Length; j++) { if (newArray[j] == '1') { result = result + e.data[j] + ","; } } result = result.Remove(result.Length - 1); result += "},"; } result = result.Remove(result.Length - 1) + "}"; return(result); }
public object Clone() { ArraySet temp = new ArraySet(); foreach (double i in this.data) { temp.add(i); } return(temp); }
public static bool isSubsetOf(ArraySet a, ArraySet b) { foreach (object i in a.data) { if (!b.contains((double)i)) { return(false); } } return(true); }
public ArraySet difference(ArraySet e) { ArraySet temp = (ArraySet)this.Clone(); foreach (double i in this.data) { if (e.contains(i)) { temp.remove(i); } } return(temp); }
public ArraySet Union(ArraySet e) { ArraySet temp = (ArraySet)this.Clone(); foreach (double j in e.data) { if (!temp.contains(j)) { temp.add(j); } } return(temp); }
public ArraySet intersection(ArraySet e) { ArraySet temp = new ArraySet(); foreach (double i in this.data) { foreach (double j in e.data) { if (i == j) { temp.add(i); break; } } } return(temp); }