Example #1
0
        /// <summary>
        /// Handles the Click event of the btnFilter control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnFilter_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (selectedCourse == null)
                {
                    MessageBox.Show("Please select course to filter by grade", "Filter", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                if (string.IsNullOrWhiteSpace(filterMin.Text))
                {
                    MessageBox.Show("Please enter correct Range", "Filter", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                if (string.IsNullOrWhiteSpace(filterMax.Text))
                {
                    MessageBox.Show("Please enter correct Range", "Filter", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                int from = Int32.Parse(filterMin.Text);
                int to   = Int32.Parse(filterMax.Text);

                var  studByCourses = DataManager.StudentsByCourse(Students, selectedCourse.Id);
                Heap heap          = new Heap()
                {
                    HeapSize = studByCourses.Length, SortedStudent = studByCourses as StudentByCourse[]
                };

                Heapsort hs = new Heapsort();
                hs.Sort(studByCourses.Length, heap);

                var filteredStudents = binarySearch.SearchRange(heap.SortedStudent, from, to);

                if (filteredStudents == null)
                {
                    return;
                }

                if (filteredStudents.Count == 0)
                {
                    MessageBox.Show("No student found", "Filter", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                gridStudents.ItemsSource = filteredStudents;
            }
            catch
            {
                MessageBox.Show("Error", "Filter", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void TestSortCase1a()
        {
            setScene1A();

            List <int> temp = heapsort.Sort(list);

            Boolean same = true;

            for (int i = 0; i < temp.Count && same; i++)
            {
                if (temp[i] != expectedResult[i])
                {
                    same = false;
                }
            }

            Assert.IsTrue(same);
        }
Example #3
0
        /// <summary>
        /// Invoke appropriate Sort algorithm on selection of 'Sort By' option
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void cmbSortBy_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selectedColumn = (sender as ComboBox).SelectedItem as string;

            IStudent[] ResultedStudent;

            if (selectedCourse == null)
            {
                if (selectedColumn == "FirstName")
                {
                    ResultedStudent = quickSort.quickSortByFirstName(StudentArray, 0, StudentArray.Length - 1);
                }
                else if (selectedColumn == "LastName")
                {
                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();

                    ResultedStudent = quickSort.quickSortByLastName(StudentArray, 0, StudentArray.Length - 1);
                    stopWatch.Stop();
                    Debug.WriteLine("Quick Sort Execution time is {0} for Array of Length {1} ", stopWatch.Elapsed, StudentArray.Length);
                }
                else if (selectedColumn == "Status")
                {
                    ResultedStudent = quickSort.quickSortByStatus(StudentArray, 0, StudentArray.Length - 1);
                }
                else
                {
                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();
                    ResultedStudent = quickSort.quickSortById(StudentArray, 0, StudentArray.Length - 1);
                    stopWatch.Stop();
                    Debug.WriteLine("Quick Sort Execution time is {0} for Array of Length {1} ", stopWatch.Elapsed, StudentArray.Length);
                }
                gridStudents.ItemsSource = null;

                if (chkDesc.IsChecked.Value)
                {
                    Stack stackToReverse = new Stack(typeof(Student), ResultedStudent.Length);

                    foreach (Student stud in ResultedStudent)
                    {
                        stackToReverse.Push(stud);
                    }

                    List <Student> reverse = new List <Student>();

                    while (!stackToReverse.IsEmpty)
                    {
                        reverse.Add(stackToReverse.Pop() as Student);
                    }

                    gridStudents.ItemsSource = reverse;
                    return;
                }

                gridStudents.ItemsSource = ResultedStudent as Student[];
                return;
            }
            else
            {
                var studByCourses = DataManager.StudentsByCourse(Students, selectedCourse.Id);

                if (selectedColumn == "GPA/TotalGrade/LetterGrade")
                {
                    Heap heap = new Heap()
                    {
                        HeapSize = studByCourses.Length, SortedStudent = studByCourses
                    };
                    heapSort.Sort(studByCourses.Length, heap);


                    if (chkDesc.IsChecked.Value)
                    {
                        Stack stackToReverse = new Stack(typeof(StudentByCourse), studByCourses.Length);

                        foreach (StudentByCourse stud in studByCourses)
                        {
                            stackToReverse.Push(stud);
                        }

                        List <StudentByCourse> reverse = new List <StudentByCourse>();

                        while (!stackToReverse.IsEmpty)
                        {
                            reverse.Add(stackToReverse.Pop() as StudentByCourse);
                        }

                        gridStudents.ItemsSource = reverse;
                        return;
                    }

                    gridStudents.ItemsSource = studByCourses;
                }
                else
                {
                    if (selectedColumn == "FirstName")
                    {
                        ResultedStudent = quickSort.quickSortByFirstName(studByCourses, 0, studByCourses.Length - 1);
                    }
                    else if (selectedColumn == "LastName")
                    {
                        Stopwatch stopWatch = new Stopwatch();
                        stopWatch.Start();

                        ResultedStudent = quickSort.quickSortByLastName(studByCourses, 0, studByCourses.Length - 1);
                        stopWatch.Stop();
                        Debug.WriteLine("Quick Sort Execution time is {0} for Array of Length {1}: ", stopWatch.Elapsed, studByCourses.Length);
                    }
                    else if (selectedColumn == "Status")
                    {
                        ResultedStudent = quickSort.quickSortByStatus(studByCourses, 0, studByCourses.Length - 1);
                    }
                    else
                    {
                        Stopwatch stopWatch = new Stopwatch();
                        stopWatch.Start();
                        ResultedStudent = quickSort.quickSortById(studByCourses, 0, studByCourses.Length - 1);
                        stopWatch.Stop();
                        Debug.WriteLine("Quick Sort Execution time is {0} for Array of Length {1} ", stopWatch.Elapsed, StudentArray.Length);
                    }

                    if (chkDesc.IsChecked.Value)
                    {
                        Stack stackToReverse = new Stack(typeof(StudentByCourse), ResultedStudent.Length);

                        foreach (StudentByCourse stud in ResultedStudent)
                        {
                            stackToReverse.Push(stud);
                        }

                        List <StudentByCourse> reverse = new List <StudentByCourse>();

                        while (!stackToReverse.IsEmpty)
                        {
                            reverse.Add(stackToReverse.Pop() as StudentByCourse);
                        }

                        gridStudents.ItemsSource = reverse;
                        return;
                    }

                    gridStudents.ItemsSource = ResultedStudent as StudentByCourse[];
                }
            }
        }
Example #4
0
 public void Given_UnsortedArray_Expect_SortedArray(int[] d, int[] e)
 {
     int[] a = Heapsort.Sort(d);
     Assert.True(Enumerable.SequenceEqual(a, e));
 }
Example #5
0
 public void Given_NullOrEmptyArray_Expect_ThrowsArgumentException(int[] d)
 {
     Assert.Throws <ArgumentException>(() => Heapsort.Sort(d));
 }