예제 #1
0
        public static void Main(string[] args)
        {
            int n = 0;

            int[] set = new int[Size];

            // this is trivial
            int x;
            int y;

            for (x = 0; x < n; x++)
            {
                for (y = x + 1; y < n; y++)
                {
                    BenchmarkException.CheckCondition(set[x] != set[y]);
                }
            }

            // we have an array of values to insert
            int[] values = new int[Size];

            // insert them in the array -- note that nothing ensures that values is not containing duplicates!
            int v;

            for (v = 0; v < Size; v++)
            {
                // check if the element exists, if not insert it.
                if (Elem_exists(set, n, values[v]))
                {
                    // parametes are passed by reference
                    n = Insert(set, n, values[v]);
                }
                for (x = 0; x < n; x++)
                {
                    for (y = x + 1; y < n; y++)
                    {
                        BenchmarkException.CheckCondition(set[x] != set[y]);
                    }
                }
            }

            // this is not trivial!
            for (x = 0; x < n; x++)
            {
                for (y = x + 1; y < n; y++)
                {
                    BenchmarkException.CheckCondition(set[x] != set[y]);
                }
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            int[] array = new int[MAX];
            int   i;
            int   largest1;
            int   largest2;
            int   temp;

            /*  assume first element of array is the first larges t*/
            largest1 = array[0];
            /*  assume first element of array is the second largest */
            largest2 = array[1];

            if (largest1 < largest2)
            {
                temp     = largest1;
                largest1 = largest2;
                largest2 = temp;
            }
            for (i = 2; i < MAX; i++)
            {
                if (array[i] >= largest1)
                {
                    largest2 = largest1;
                    largest1 = array[i];
                }
                else if (array[i] > largest2)
                {
                    largest2 = array[i];
                }
            }

            int x;

            for (x = 0; x < MAX; x++)
            {
                BenchmarkException.CheckCondition(array[x] <= largest1);
            }
            for (x = 0; x < MAX; x++)
            {
                BenchmarkException.CheckCondition(array[x] <= largest2 || array[x] == largest1);
            }
        }