Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        // function to input a set as an int array
        static IntegerSet InputSet()
        {
            // reads in the input as a string
            string input = Console.ReadLine();

            // splits the string into an array of strings
            string[] nums = input.Split();
            // creates an array which will store the numbers as integers
            int[] cleanNumbers = new int[nums.Length];
            // loops through the string array and converts the strings to integers
            for (int i = 0; i < nums.Length; i++)
            {
                cleanNumbers[i] = int.Parse(nums[i]);
            }
            // converts the integer array into an integer set
            IntegerSet s = new IntegerSet(cleanNumbers);

            return(s);
        }