public static Set operator +(Set ob, char ch) { if(ob.find(ch) != -1) { return new Set(ob); } else { Set newset = new Set(ob.Length + 1); for(int i = 0; i < ob.Length; i++) newset.members[i] = ob.members[i]; newset.Length = ob.Length + 1; newset.members[newset.Length - 1] = ch; return newset; } }
public static Set operator +(Set ob1, Set ob2) { Set newset = new Set(ob1); for(int i =0; i < ob2.Length; i++) newset = newset + ob2[i]; return newset; }
public static Set operator -(Set ob, char ch) { Set newset = new Set(); int i = ob.find(ch); for(int j =0; j < ob.Length; j++) if(j != i) newset = newset + ob.members[j]; return newset; }
public Set(Set s) { members = new char[s.Length]; for(int i=0; i < s.Length; i++) members[i] = s.members[i]; Length = s.Length; }
public static void SetDemoStart() { Set s1 = new Set(); Set s2 = new Set(); Set s3 = new Set(); s1 = s1 + 'A'; s1 = s1 + 'B'; s1 = s1 + 'C'; Console.Write("s1 after adding A B C: "); for(int i=0; i<s1.Length; i++) Console.Write(s1[i] + " "); Console.WriteLine(); s1 = s1 - 'B'; Console.Write("s1 after s1 = s1 - 'B': "); for(int i=0; i<s1.Length; i++) Console.Write(s1[i] + " "); Console.WriteLine(); s1 = s1 - 'A'; Console.Write("s1 after s1 = s1 - 'A': "); for(int i=0; i<s1.Length; i++) Console.Write(s1[i] + " "); Console.WriteLine(); s1 = s1 - 'C'; Console.Write("s1 after s1 = s1 - 'C': "); for(int i=0; i<s1.Length; i++) Console.Write(s1[i] + " "); Console.WriteLine("\n"); s1 = s1 + 'A'; s1 = s1 + 'B'; s1 = s1 + 'C'; Console.Write("s1 after adding A B C: "); for(int i=0; i<s1.Length; i++) Console.Write(s1[i] + " "); Console.WriteLine(); s2 = s2 + 'A'; s2 = s2 + 'X'; s2 = s2 + 'W'; Console.Write("s2 after adding A X W: "); for(int i=0; i<s2.Length; i++) Console.Write(s2[i] + " "); Console.WriteLine(); s3 = s1 + s2; Console.Write("s3 after s3 = s1 + s2: "); for(int i=0; i<s3.Length; i++) Console.Write(s3[i] + " "); Console.WriteLine(); s3 = s3 - s1; Console.Write("s3 after s3 - s1: "); for(int i=0; i<s3.Length; i++) Console.Write(s3[i] + " "); Console.WriteLine("\n"); Console.WriteLine(); s2 = s2 - s2; s2 = s2 + 'C'; s2 = s2 + 'B'; s2 = s2 + 'A'; s1 = s1 + 'D'; s1 = s1 + 'E'; s2 = s2 + 'E'; Console.Write("s1 is now: "); for(int i=0; i<s1.Length; i++) Console.Write(s1[i] + " "); Console.WriteLine(); Console.Write("s2 is now: "); for(int i=0; i<s2.Length; i++) Console.Write(s2[i] + " "); Console.WriteLine(); Console.Write("s3 is now: "); for(int i=0; i<s3.Length; i++) Console.Write(s3[i] + " "); Console.WriteLine(); Console.WriteLine(); }