public void testBinarySearch()
        {
            var input = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var res   = SearchAndSort.BinarySearch(input, 3, 0, 8);

            Assert.AreEqual(2, res);

            input = new int[] { 10, 20, 33, 46, 51, 69, 71, 82, 98, 101, 567, 1000 };
            res   = SearchAndSort.BinarySearch(input, 567, 0, 11);
            Assert.AreEqual(10, res);

            input = new int[] { 10, 20, 33, 46, 51, 69, 71, 82, 98, 101, 567, 1000 };
            res   = SearchAndSort.BinarySearch(input, 10, 0, 11);
            Assert.AreEqual(0, res);

            input = new int[] { 10, 20, 33, 46, 51, 69, 71, 82, 98, 101, 567, 1000 };
            res   = SearchAndSort.BinarySearch(input, 1000, 0, 11);
            Assert.AreEqual(11, res);


            input = new int[] { 10, 20, 33, 46, 51, 69, 71, 82, 98, 101, 567, 1000 };
            res   = SearchAndSort.BinarySearch(input, 5, 0, 11);
            Assert.AreEqual(-1, res);


            input = new int[] { 10, 20, 33, 46, 51, 69, 71, 82, 98, 101, 567, 1000 };
            res   = SearchAndSort.BinarySearch(input, 2000, 0, 11);
            Assert.AreEqual(-1, res);
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     int[] arr1 = new int[10];
     int[] arr2 = new int[15];
     for (int i = arr1.Length - 1; i >= 0; --i)
     {
         arr1[i] = random.Next(MAX);
     }
     for (int i = arr2.Length - 1; i >= 0; --i)
     {
         arr2[i] = random.Next(MAX);
     }
     SearchAndSort.SortInsertion(arr1);
     SearchAndSort.SortInsertion(arr2);
     printNumbers(arr1);
     printNumbers(arr2);
     printShared1(arr1, arr2);
 }
        public async Task <ApiResult> SearchAndSortStudentsAsync(SearchAndSort searchAndSort)
        {
            var systemUsers = default(IQueryable <SystemUser>);

            var allUsers = context.SystemUsers
                           .GetOnlyUsers();

            var amount = await allUsers.CountAsync();

            var pagination = new Pagination();

            pagination.SetDefaults(amount, pageSize: 5);

            searchAndSort.Pagination ??= pagination;

            var skip = searchAndSort.Pagination
                       .GetSkip();

            var take = searchAndSort.Pagination
                       .GetTake();

            if (searchAndSort.IsSearch)
            {
                systemUsers = allUsers.SearchStudents(searchAndSort.SearchField)
                              .GetSortedUsers(searchAndSort.Sort);
            }
            else
            {
                systemUsers = allUsers.GetSortedUsers(searchAndSort.Sort);
            }

            var students = await systemUsers.GetPortionOfQueryable(skip, take)
                           .ToArrayAsync();

            var users = mapperWrapper.MapModels(students);

            var data = new { pagination = searchAndSort.Pagination, users = users };

            var result = ApiResult.GetOkResult(ApiResultStatus.Ok, data: data);

            return(result);
        }
        public void testBubbleSort()
        {
            var input = new int[] { 5, 6, 1, 3, 7, 0, 8, 9, 4, 2 };

            SearchAndSort.BubbleSort(input);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
start:
            Console.WriteLine("Data structures and Algorithm \n");

            Console.WriteLine("" +
                              "Please enter the Algorithm paradigm number. \n" +
                              "*******************************************\n" +
                              "1. Divide and Conqure \n" +
                              "2. Greedy Algorithms \n" +
                              "3. Dynamic Programming \n" +
                              "4. Search And Sort Algorithms \n" +
                              "5. Other Algorithms \n" +
                              "6. Exit \n" +
                              "******************************************* \n\n" +
                              "Please enter your choice\n"

                              );

            int algoSec = Convert.ToInt16(Console.ReadLine());
            int algoNum;

            switch (algoSec)
            {
            case 1:
                Console.WriteLine(
                    "Divide And Conqure \n \n" +
                    "******************\n" +
                    "1. Binary Search \n" +
                    "2. Merge Sort \n" +
                    "3. Quick Sort \n" +
                    "4. Closest Pair of Points \n" +
                    "5. Strassen's Matrix Multiplication \n" +
                    "6. Karatsuba Multiplication \n" +
                    "7. Cooley-Tukey Fast Fourier Transformation \n" +
                    "8. Multiply 2 Polynomials \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );

                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    DivideAndConquer.BinarySearch();
                    goto start;

                case 2:
                    DivideAndConquer.MergeSort();
                    goto start;

                case 3:
                    DivideAndConquer.QuickSortMain();
                    goto start;

                case 4:
                    DivideAndConquer.ClosestPairOfPoint();
                    goto start;

                case 5:
                    DivideAndConquer.MatrixMultiplication();
                    goto start;

                case 6:
                    DivideAndConquer.KaratsubaMultiplication();
                    goto start;

                case 7:
                    DivideAndConquer.CooleyTukeyFTT();
                    goto start;

                case 8:
                    DivideAndConquer.MultiplyTwoPolynomial();
                    goto start;
                }

                break;

            case 2:
                Console.WriteLine(
                    "Greedy Algorithm \n \n" +
                    "*****************\n" +
                    "1. \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    goto start;
                }

                break;

            case 3:
                Console.WriteLine(
                    "Dynamic Programming\n \n" +
                    "*****************\n" +
                    "1. \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    goto start;
                }

                break;

            case 4:
                Console.WriteLine(
                    "Search and Sorting Algorithm \n \n" +
                    "*****************************\n" +
                    "1. Linear Search \n" +
                    "2. Selection Sort \n" +
                    "3. Insertion Sort \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    SearchAndSort.LinearSearch();
                    goto start;

                case 2:
                    SearchAndSort.SelectionSortAlgo();
                    goto start;

                case 3:
                    SearchAndSort.InsertionSort();
                    goto start;
                }
                break;

            case 5:
                Console.WriteLine(
                    "Other Algorithms \n \n" +
                    "****************\n" +
                    "1.  \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    goto start;
                }
                break;

            case 6:
                Environment.Exit(0);
                break;
            }
        }
Beispiel #6
0
        public async Task <IActionResult> SearchStudents([FromBody] SearchAndSort searchAndSort)
        {
            var result = await studentsService.SearchAndSortStudentsAsync(searchAndSort);

            return(this.GetActionResult(result, logger));
        }