コード例 #1
0
        static async void MainAsync()
        {
            // initialize two sets
            Console.WriteLine("Input Set A");
            IntegerSet set1 = InputSet();

            Console.WriteLine("\nInput Set B");
            IntegerSet set2 = InputSet();

            Task <IntegerSet> unionTask        = Task.Run(() => set1.Union(set2));
            Task <IntegerSet> intersectionTask = Task.Run(() => set1.Intersection(set2));

            await Task.WhenAll(unionTask, intersectionTask);

            // prepare output
            Console.WriteLine("\nSet A contains elements:");
            Console.WriteLine(set1.ToString());
            Console.WriteLine("\nSet B contains elements:");
            Console.WriteLine(set2.ToString());
            Console.WriteLine(
                "\nUnion of Set A and Set B contains elements:");
            Console.WriteLine(unionTask.ToString());
            Console.WriteLine(
                "\nIntersection of Set A and Set B contains elements:");
            Console.WriteLine(intersectionTask.ToString());

            // test whether two sets are equal
            if (set1.IsEqualTo(set2))
            {
                Console.WriteLine("\nSet A is equal to set B");
            }
            else
            {
                Console.WriteLine("\nSet A is not equal to set B");
            }

            // test insert and delete
            Console.WriteLine("\nInserting 77 into set A...");
            set1.InsertElement(77);
            Console.WriteLine("\nSet A now contains elements:");
            Console.WriteLine(set1.ToString());

            Console.WriteLine("\nDeleting 77 from set A...");
            set1.DeleteElement(77);
            Console.WriteLine("\nSet A now contains elements:");
            Console.WriteLine(set1.ToString());

            // test constructor
            int[]      intArray = { 25, 67, 2, 9, 99, 105, 45, -5, 100, 1 };
            IntegerSet set3     = new IntegerSet(intArray);

            Console.WriteLine("\nNew Set contains elements:");
            Console.WriteLine(set3.ToString());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: raymanan11/CECS-475
        static IntegerSet InputSet()
        {
            IntegerSet result = new IntegerSet();

            while (true)
            {
                Console.Write("Enter number (-1 to end): ");
                int inputNum = Convert.ToInt32(Console.ReadLine());
                if (inputNum != -1)
                {
                    result.InsertElement(inputNum);
                }
                else
                {
                    return(result);
                }
            }
        }