Example #1
0
        static void Main(string[] args)
        {
            double[]       array    = new double[] { 2, 3, 23, 6, 66, 4, 45, 576, 55, 2, 4, 365, 33, 73, 103, 33, 86, 55, 25, 56, 366, 99, 399, 5, 27, 11, 2, 222, 40, 255, 0, 425 };
            NumberSequence sequence = new NumberSequence(array);

            sequence.SetSortStrategy(new BubbleSort());
            sequence.SetSearchStrategy(new LinearSearch());
            int numberToSerachFor = 7;

            Console.WriteLine(sequence.Search(numberToSerachFor));
            sequence.Sort();
            Console.WriteLine(sequence.Search(numberToSerachFor));
        }
        static void Main(string[] args)
        {
            //1. Zadatak

            double[] numbers = new double[] { 7, 4, 6, 14, 9, 1, 3, 2, 0, 12, 5 };

            NumberSequence sequentialSortSequence = new NumberSequence(numbers);

            sequentialSortSequence.SetSortStrategy(new SequentialSort());

            NumberSequence bubbleSortSequence = new NumberSequence(numbers);

            bubbleSortSequence.SetSortStrategy(new BubbleSort());

            NumberSequence combSortSequence = new NumberSequence(numbers);

            combSortSequence.SetSortStrategy(new CombSort());

            sequentialSortSequence.Sort();
            bubbleSortSequence.Sort();
            combSortSequence.Sort();

            Console.WriteLine(sequentialSortSequence.ToString());
            Console.WriteLine(bubbleSortSequence.ToString());
            Console.WriteLine(combSortSequence.ToString());



            //2. Zadatak
            NumberSequence numberSequence = new NumberSequence(numbers);

            numberSequence.SetSearchStrategy(new SeqSearch());

            Console.WriteLine(numberSequence.Search(7));
            Console.WriteLine(numberSequence.Search(14));



            //3. i 4. Zadatak
            SystemDataProvider dataProvider = new SystemDataProvider();

            dataProvider.Attach(new FileLogger("data.txt"));
            dataProvider.Attach(new ConsoleLogger());

            while (true)
            {
                dataProvider.GetCPULoad();
                dataProvider.GetAvailableRAM();
                System.Threading.Thread.Sleep(1000);
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            NumberSequence sequence       = new NumberSequence(new double[] { 8, 2, 1, 7, 6, 5, 4, 3, 10, 9 });
            NumberSequence sequencebubble = sequence;
            NumberSequence sequencecomb   = sequence;

            sequence.SetSortStrategy(new SequentialSort());
            sequencebubble.SetSortStrategy(new BubbleSort());
            sequencecomb.SetSortStrategy(new CombSort());
            sequence.Sort();
            Console.WriteLine("Sequential sort:");
            Console.WriteLine(sequence.ToString());
            sequencebubble.Sort();
            Console.WriteLine("Bubble sort:");
            Console.WriteLine(sequencebubble.ToString());
            sequencecomb.Sort();
            Console.WriteLine("Comb sort:");
            Console.WriteLine(sequencecomb.ToString());

            sequence.SetSearchStrategy(new LinearSearch());
            int index = sequence.Search(11);

            if (index != -1)
            {
                Console.WriteLine("Index of given number in the array: " + index);
            }
            else
            {
                Console.WriteLine("There is not given number in the array!");
            }
            int index1 = sequence.Search(10);

            if (index1 != -1)
            {
                Console.WriteLine("Index of given number in the array: " + index1);
            }
            else
            {
                Console.WriteLine("There is not given number in the array!");
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            double[]       array    = new double[] { -65, -10, -8, -6, -4, 0, 2, 5, 8, 10, 16 };
            NumberSequence sequence = new NumberSequence(array);
            //BubbleSort bubble = new BubbleSort();
            //sequence.SetSortStrategy(bubble);

            //Console.WriteLine("Unsorted array:\n" + sequence.ToString());

            //sequence.Sort();
            //Console.WriteLine("Sorted array:\n" + sequence.ToString()); // ZADATAK 1
            LinearSearch linearSearch = new LinearSearch();

            sequence.SetSearchStrategy(linearSearch);
            Console.WriteLine(sequence.Search(66));          // ZADATAK 2
        }