Beispiel #1
0
        private void Canvas1_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (canvas1.ActualHeight - 115 > 125)
            {
                Canvas.SetTop(ButtonGrid, canvas1.ActualHeight - 110);
            }
            ButtonRainbow temp_obj = new ButtonRainbow(ArraySize);

            if (temp_obj.GetButtons(ArraySize - 1) != null)
            {
                for (int i = 1; i <= ArraySize - 1; i++)
                {
                    Button a = temp_obj.GetButtons(i);
                    canvas1.Children.Remove(a);
                    if (canvas1.ActualHeight - 200 > 0)
                    {
                        a.Height = (canvas1.ActualHeight - 200);
                    }

                    a.Width = (canvas1.ActualWidth - 80) / (ArraySize - 1);
                    Canvas.SetLeft(a, 40 + (a.Width * (i - 1)));

                    canvas1.Children.Add(a);
                }
            }
        }
Beispiel #2
0
        //Insert sort
        public async void InsertSort()
        {
            //Object of ButtonRaindbow class
            ButtonRainbow RnbwBtn = new ButtonRainbow(ArraySize);

            int[] Temp_Array = Random_Array;

            for (int i = 1; i < Temp_Array.Length; i++)
            {
                SkipButton.IsEnabled = true;
                label1.Content       = i;
                int j = 0;

                for (j = i; j >= 2 &&
                     (Temp_Array[j - 1] > Temp_Array[j]); j--)
                {
                    int tmp = Temp_Array[j - 1];
                    Temp_Array[j - 1] = Temp_Array[j];
                    Temp_Array[j]     = tmp;

                    RnbwBtn.SetRGBColorForButton(j, Temp_Array);
                    RnbwBtn.SetRGBColorForButton(j - 1, Temp_Array);

                    label3.Content = Int32.Parse(label3.Content.ToString()) + 1;

                    //Delay between iterations
                    do
                    {
                        if (!Skipflag)
                        {
                            await Task.Delay(Sorting_Delay);
                        }
                        if (PauseFlag)
                        {
                            await Task.Delay(1);

                            SkipButton.IsEnabled = false;
                        }
                    } while (PauseFlag);
                }
            }
            button0.IsEnabled      = true;
            button1.IsEnabled      = false;
            comboBox1.IsEnabled    = true;
            CreatingSize.IsEnabled = true;
            Skipflag             = false;
            SkipButton.IsEnabled = false;
        }
Beispiel #3
0
        //обработчик кнопки build random rainbow
        private async void Button0_Click(object sender, RoutedEventArgs e)
        {
            button0.IsEnabled = false;
            PauseFlag         = false;
            button1.IsEnabled = true;
            button1.Content   = "Start";

            ButtonRainbow RnbwBtn = new ButtonRainbow(ArraySize);

            Random_Array = RnbwBtn.Random_Rainbow_Array;
            await RnbwBtn.CreateButtons(canvas1);

            button1.IsEnabled = true;

            e.Handled = true;
        }
Beispiel #4
0
        //сортировка пузырьком
        public async void BubbleSort()
        {
            ButtonRainbow rainbow = new ButtonRainbow(ArraySize);

            int[] arr = Random_Array;
            int   temp;

            for (int i = 0; i < arr.Length; i++)
            {
                SkipButton.IsEnabled = true;
                label1.Content       = i;
                for (int j = i + 1; j < arr.Length; j++)
                {
                    if (arr[i] > arr[j])
                    {
                        temp   = arr[i];
                        arr[i] = arr[j];
                        arr[j] = temp;

                        rainbow.SetRGBColorForButton(j, arr);
                        rainbow.SetRGBColorForButton(i, arr);

                        label3.Content = Int32.Parse(label3.Content.ToString()) + 1;
                        do
                        {
                            if (!Skipflag)
                            {
                                await Task.Delay(Sorting_Delay);
                            }
                            if (PauseFlag)
                            {
                                await Task.Delay(1);

                                SkipButton.IsEnabled = false;
                            }
                        } while (PauseFlag);
                    }
                }
            }
            button0.IsEnabled      = true;
            button1.IsEnabled      = false;
            comboBox1.IsEnabled    = true;
            CreatingSize.IsEnabled = true;
            Skipflag             = false;
            SkipButton.IsEnabled = false;
        }
Beispiel #5
0
        //шейкерная сортировка
        public async void ShakerSort()
        {
            SkipButton.IsEnabled = true;
            ButtonRainbow rainbow = new ButtonRainbow(ArraySize);

            int[] array = Random_Array;
            int   temp;

            for (var i = 0; i < array.Length / 2; i++)
            {
                SkipButton.IsEnabled = true;
                label1.Content       = i;
                var swapFlag = false;

                for (var j = i; j < array.Length - i - 1; j++)
                {
                    if (array[j] > array[j + 1])
                    {
                        temp         = array[j];
                        array[j]     = array[j + 1];
                        array[j + 1] = temp;

                        swapFlag = true;

                        rainbow.SetRGBColorForButton(j + 1, array);
                        rainbow.SetRGBColorForButton(j, array);

                        label3.Content = Int32.Parse(label3.Content.ToString()) + 1;
                        do
                        {
                            if (!Skipflag)
                            {
                                await Task.Delay(Sorting_Delay);
                            }
                            if (PauseFlag)
                            {
                                await Task.Delay(1);

                                SkipButton.IsEnabled = false;
                            }
                        } while (PauseFlag);
                    }
                }

                for (var j = array.Length - 2 - i; j > i; j--)
                {
                    if (array[j - 1] > array[j])
                    {
                        temp         = array[j - 1];
                        array[j - 1] = array[j];
                        array[j]     = temp;

                        swapFlag = true;

                        rainbow.SetRGBColorForButton(j, array);
                        rainbow.SetRGBColorForButton(j - 1, array);

                        label3.Content = Int32.Parse(label3.Content.ToString()) + 1;
                        do
                        {
                            if (!Skipflag)
                            {
                                await Task.Delay(Sorting_Delay);
                            }
                            if (PauseFlag)
                            {
                                await Task.Delay(1);

                                SkipButton.IsEnabled = false;
                            }
                        } while (PauseFlag);
                    }
                }

                if (!swapFlag)
                {
                    break;
                }
                do
                {
                    if (!Skipflag)
                    {
                        await Task.Delay(Sorting_Delay);
                    }
                    if (PauseFlag)
                    {
                        await Task.Delay(1);

                        SkipButton.IsEnabled = false;
                    }
                } while (PauseFlag);
            }
            CreatingSize.IsEnabled = true;
            comboBox1.IsEnabled    = true;
            button0.IsEnabled      = true;
            button1.IsEnabled      = false;
            Skipflag             = false;
            SkipButton.IsEnabled = false;
        }