Exemplo n.º 1
0
        void SearchItemPicker_SelectedIndexChanged(object sender, EventArgs e)
        {
            ToggleSearchBtn();
            SearchingGraphObject SGObj = (SearchingGraphObject)BindingContext;
            // change colour of old entry
            Entry oldEntry = CurrentEntriesOnGraph.Where(p => p.Value == SGObj.SearchItemValue)
                             .FirstOrDefault();

            if (!(oldEntry is null))
            {
                oldEntry.Color = SKColor.Parse("#FF1493");
            }

            SGObj.SearchItemValue = searchItemPicker.SelectedIndex;
            Entry searchItemEntry = CurrentEntriesOnGraph.Where(p => p.Value == SGObj.SearchItemValue)
                                    .FirstOrDefault();

            int index = CurrentEntriesOnGraph.ToList().IndexOf(searchItemEntry);

            if (SGObj.SearchItemValue > 0)
            {
                CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse("#0000FF");
            }
            DisplayGraph(CurrentEntriesOnGraph);
        }
Exemplo n.º 2
0
        private async void CarryOutOperations <T>(List <T> operations) where T : ISortOperation
        {
            SortingGraphObject SGObj = (SortingGraphObject)BindingContext;
            int speed = SGObj.SpeedDictionary[SGObj.Speed];

            foreach (T operation in operations)
            {
                int index;
                foreach (Entry entry in operation.EntriesToChange)
                {
                    index = CurrentEntriesOnGraph.IndexOf(entry);
                    if (index > 0)
                    {
                        CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(operation.ChangeToColour);
                    }
                }
                DisplayGraph(operation.NewEntries);
                await Task.Delay(speed);

                CurrentEntriesOnGraph = (Entry[])operation.NewEntries;
                DisplayGraph(CurrentEntriesOnGraph);
                foreach (Entry entry in operation.EntriesToChange)
                {
                    // change colour back to red
                    index = CurrentEntriesOnGraph.IndexOf(entry);
                    CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(App.GraphColour);
                }
            }
            ToggleButtons();
            DisplayCaseBtns();
        }
Exemplo n.º 3
0
        private async void CarryOutMergeOperations(List <MergeSortOperation> operations)
        {
            foreach (MergeSortOperation operation in operations)
            {
                SortingGraphObject SGObj = (SortingGraphObject)BindingContext;
                int speed = SGObj.SpeedDictionary[SGObj.Speed];
                if (!operation.IsFinalMergeOperation)
                {
                    foreach (Entry entry in operation.LeftEntries)
                    {
                        Entry tempEntry = CurrentEntriesOnGraph.Where(hr => hr.Value == entry.Value).FirstOrDefault();
                        if (tempEntry != null)
                        {
                            continue;                           // doesn't f*cking work
                        }
                    }

                    DisplayGraph(CurrentEntriesOnGraph);
                    await Task.Delay(speed);
                }
                else
                {
                    CurrentEntriesOnGraph = operation.LeftEntries
                                            .Concat(operation.RightEntries)
                                            .ToList();
                    DisplayGraph(CurrentEntriesOnGraph);
                    await Task.Delay(speed);

                    int   resultValue = (int)operation.ResultsEntries.Last().Value;
                    Entry entry       = CurrentEntriesOnGraph.Where(hr => hr.Value == resultValue)
                                        .FirstOrDefault();
                    if (entry != null)
                    {
                        List <Entry> entries = CurrentEntriesOnGraph.Select(hr => hr).ToList();
                        entries.Remove(entry);
                        entries.Add(entry);
                        CurrentEntriesOnGraph = entries;
                        DisplayGraph(CurrentEntriesOnGraph);
                        await Task.Delay(speed);
                    }
                }
            }
            ToggleButtons();
            DisplayCaseBtns();
        }
Exemplo n.º 4
0
 private async void ClearMarkersOnGraph(IEnumerable <Entry> markers)
 {
     if (markers != null &&
         markers.Count() != 0)
     {
         SearchingGraphObject SGObj = (SearchingGraphObject)BindingContext;
         // change colour of current markers back
         foreach (Entry marker in markers)
         {
             if (marker.Value != SGObj.SearchItemValue)
             {
                 int index = CurrentEntriesOnGraph.ToList().IndexOf(marker);
                 CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(App.GraphColour);
                 DisplayGraph(CurrentEntriesOnGraph);
                 await Task.Delay(SGObj.SpeedDictionary[SGObj.Speed]);
             }
         }
         CurrentMarkers.Clear();
     }
 }
Exemplo n.º 5
0
        private async Task ChangeOperationEntry <T>(T operation) where T : ISearchOperation
        {
            if (operation.Entry != null)
            {
                SearchingGraphObject SGObj = (SearchingGraphObject)BindingContext;
                int index = CurrentEntriesOnGraph.ToList().IndexOf(operation.Entry);
                if (operation.IsSearchItem is false)
                {
                    Console.WriteLine(index);
                    CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(operation.ChangeToColour);
                    DisplayGraph(CurrentEntriesOnGraph);
                    await Task.Delay(SGObj.SpeedDictionary[SGObj.Speed]);

                    // change back to original colour
                    CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(App.GraphColour);
                }
                else if (operation.IsSearchItem is true)
                {
                    CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(operation.ChangeToColour);
                }
                DisplayGraph(CurrentEntriesOnGraph);
            }
        }
Exemplo n.º 6
0
        private async Task HandleMarkers(InterpolationOperation operation)
        {
            if (operation.Markers != null &&
                operation.Markers.Length != 0)
            {
                SearchingGraphObject SGObj = (SearchingGraphObject)BindingContext;
                if (CurrentMarkers.Count() != 0)
                {
                    // change colour of current markers on graph
                    ClearMarkersOnGraph(CurrentMarkers);
                    await Task.Delay(SGObj.SpeedDictionary[SGObj.Speed]);
                }

                // add new markers
                foreach (Entry entry in operation.Markers)
                {
                    int index = CurrentEntriesOnGraph.ToList().IndexOf(entry);
                    CurrentEntriesOnGraph.ToArray()[index].Color = SKColor.Parse(operation.ChangeToColour);
                    CurrentMarkers.Add(entry);
                }
                DisplayGraph(CurrentEntriesOnGraph);
                await Task.Delay(SGObj.SpeedDictionary[SGObj.Speed]);
            }
        }
Exemplo n.º 7
0
        void SortBtnIsClicked(object sender, EventArgs e)
        {
            SortingGraphObject SGObj = (SortingGraphObject)BindingContext;

            if (IsSorted(CurrentEntriesOnGraph) is true)
            {
                ResetGraph();
            }
            if (SGObj.CurrentAlg != "" ||
                SGObj.CurrentAlg != null)
            {
                ToggleButtons();
                switch (SGObj.CurrentAlg)
                {
                case "Bubble Sort":
                {
                    IEnumerable <SortOperation> operations = algorithms.BubbleSort(CurrentEntriesOnGraph.ToArray());
                    CarryOutOperations(operations.ToList());
                    break;
                }

                case "Heap Sort":
                {
                    IEnumerable <SortOperation> operations = algorithms.HeapSort(CurrentEntriesOnGraph.ToArray());
                    CarryOutOperations(operations.ToList());
                    break;
                }

                case "Insertion Sort":
                {
                    IEnumerable <SortOperation> operations = algorithms.InsertionSort(CurrentEntriesOnGraph.ToArray());
                    CarryOutOperations(operations.ToList());
                    break;
                }

                case "Merge Sort":
                {
                    IEnumerable <MergeSortOperation> operations = algorithms.MergeSort(CurrentEntriesOnGraph.ToArray());
                    CarryOutMergeOperations(operations.ToList());
                    break;
                }

                case "Quick Sort":
                {
                    List <SortOperation> ops        = new List <SortOperation>();
                    List <SortOperation> operations = algorithms.QuickSort(CurrentEntriesOnGraph.ToArray(),
                                                                           0,
                                                                           SGObj.GraphElementNumber - 1,
                                                                           ops);
                    CarryOutOperations(operations);
                    break;
                }

                case "Selection Sort":
                {
                    IEnumerable <SortOperation> operations = algorithms.SelectionSort(CurrentEntriesOnGraph.ToArray());
                    CarryOutOperations(operations.ToList());
                    break;
                }

                default:
                    break;
                }
            }
        }
Exemplo n.º 8
0
        async void SearchBtnIsClicked(object sender, EventArgs e)
        {
            SearchingGraphObject SGObj = (SearchingGraphObject)BindingContext;

            if (SGObj.SearchItemValue > 0)
            {
                ToggleButtons();
                switch (SGObj.CurrentAlg)
                {
                case "Linear Search":
                {
                    IEnumerable <SearchOperation> operations = algorithms.LinearSearch(CurrentEntriesOnGraph.ToArray(),
                                                                                       SGObj.SearchItemValue);
                    CarryOutSearchOperations(operations.ToList());
                    break;
                }

                case "Jump Search":
                {
                    IEnumerable <SearchOperation> operations = algorithms.JumpSearch(CurrentEntriesOnGraph.ToArray(),
                                                                                     SGObj.SearchItemValue);
                    CarryOutSearchOperations(operations.ToList());
                    break;
                }

                case "Classic Binary Search":
                {
                    IEnumerable <SearchOperation> operations = algorithms.ClassicBinarySearch(CurrentEntriesOnGraph.ToArray(),
                                                                                              SGObj.SearchItemValue);
                    CarryOutSearchOperations(operations.ToList());
                    break;
                }

                case "Modified Binary Search":
                {
                    IEnumerable <SearchOperation> operations = algorithms.ModifiedBinarySearch(CurrentEntriesOnGraph.ToArray(),
                                                                                               SGObj.SearchItemValue);
                    CarryOutSearchOperations(operations.ToList());
                    break;
                }

                case "Interpolation Search":
                {
                    IEnumerable <InterpolationOperation> operations = algorithms.InterpolationSearch(CurrentEntriesOnGraph.ToArray(),
                                                                                                     SGObj.SearchItemValue);
                    CarryOutInterpolationOperations(operations.ToList());
                    break;
                }

                case "Fibonacci Search":
                {
                    IEnumerable <SearchOperation> operations = algorithms.FibonacciSearch(CurrentEntriesOnGraph.ToArray(),
                                                                                          SGObj.SearchItemValue);
                    CarryOutSearchOperations(operations.ToList());
                    break;
                }

                default:
                    break;
                }
            }
            else
            {
                await DisplayAlert("Error",
                                   "Select a Search Item",
                                   "Ok");
            }
        }