Esempio n. 1
0
        /// <summary>
        /// Returns the median of the values ​​of an array
        /// </summary>
        public static int Median(int[] listInteger)
        {
            int median = 0;

            if (listInteger.Length == 0)
            {
                throw new Exception("The array is empty");
            }
            if (listInteger == null)
            {
                throw new Exception("The array no exist");
            }

            int[] listOrder     = AuxiliaryMethods.OrderListLessBigger(listInteger);
            int   countElements = listOrder.Length;
            int   quotient      = countElements / 2;

            if (countElements % 2 == 0)
            {
                median = (listOrder[quotient] + listOrder[(quotient - 1)]) / 2;
            }
            else
            {
                median = listInteger[quotient];
            }
            return(median);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines the second largest number
        /// </summary>
        public static int SecondLargest(int[] listNumber)
        {
            if (listNumber.Length == 0)
            {
                throw new Exception("The array is empty");
            }
            if (listNumber == null)
            {
                throw new Exception("The array no exist");
            }

            int[] listOrder     = AuxiliaryMethods.OrderListLessBigger(listNumber);
            int   secondLargest = listOrder.Length - 2;

            return(secondLargest);
        }