private void SortButton_Click( object sender, EventArgs e ) { if( AlgoVisTabControl.TabPages.Count == 0 ) { NewTabButton_Click( null, null ); } if( string.IsNullOrEmpty( AmountTextBox.Text ) || AlgosComboBox.SelectedItem == null || _values == null ) return; #region Prepare the algo config var algoConfig = new AlgoConfig() { SortingAlgorithm = AlgosComboBox.SelectedItem as ISort, Array = ( new List<double>( _values ) ).ToArray(), PlaySound = PlaySoundCheckBox.Checked }; #endregion #region Visualize it var tabPage = AlgoVisTabControl.SelectedTab; var sortingAlgorythmVisualizerUserControl = tabPage.Controls[0] as SortingAlgorithmVisualizer; sortingAlgorythmVisualizerUserControl.Visualize( algoConfig ); #endregion }
private void SortButton_Click(object sender, EventArgs e) { if (AlgoVisTabControl.TabPages.Count == 0) { NewTabButton_Click(null, null); } if (string.IsNullOrEmpty(AmountTextBox.Text) || AlgosComboBox.SelectedItem == null || _values == null) { return; } #region Prepare the algo config var algoConfig = new AlgoConfig() { SortingAlgorithm = AlgosComboBox.SelectedItem as ISort, Array = (new List <double>(_values)).ToArray(), PlaySound = PlaySoundCheckBox.Checked }; #endregion #region Visualize it var tabPage = AlgoVisTabControl.SelectedTab; var sortingAlgorythmVisualizerUserControl = tabPage.Controls[0] as SortingAlgorithmVisualizer; sortingAlgorythmVisualizerUserControl.Visualize(algoConfig); #endregion }
public void Visualize(AlgoConfig algoConfig) { _algoConfig = algoConfig; algoConfig.SortingAlgorithm.ItemsCompared += SortingAlgorithm_ItemsCompared; algoConfig.SortingAlgorithm.ItemsSwaped += SortingAlgorythm_ItemsSwaped; algoConfig.SortingAlgorithm.ItemCopied += SortingAlgorythm_ItemCopied; algoConfig.SortingAlgorithm.Finished += SortingAlgorithm_Finished; // Update the Ui this.Parent.Text = algoConfig.SortingAlgorithm.Name; this.HowItWorksTextBox.Text = algoConfig.SortingAlgorithm.HowItWorks; this.LabelN.Text = string.Format("{0}", algoConfig.Array.Length); // Show the initial array _values = algoConfig.Array; _compares = 0; _swaps = 0; _copies = 0; LabelCompares.Text = string.Empty; LabelSwaps.Text = string.Empty; LabelCopies.Text = string.Empty; LabelBigO.Text = string.Empty; LabelTotalOperations.Text = string.Empty; _isPause = false; _autoBlockAfterOneOperation = false; _manualResetEvent.Set(); if (_task != null) { _task.Abort(); } this.BarChart.GraphPane.CurveList.Clear(); this.BarChart.GraphPane.GraphObjList.Clear(); PointPairList list = new PointPairList(); Random rand = new Random(); for (int i = 0; i < _values.Length; i++) { list.Add(i, _values[i], 0); } BarItem myCurve = this.BarChart.GraphPane.AddBar(string.Empty, list, Color.Black); // 0 1 2 3 4 myCurve.Bar.Fill = new Fill(new Color[] { Color.Black, Color.Red, Color.Yellow, Color.Blue }); // , Color.Green myCurve.Bar.Fill.Type = FillType.GradientByZ; myCurve.Bar.Fill.RangeMin = 0; myCurve.Bar.Fill.RangeMax = 3; this.BarChart.GraphPane.AxisChange(); this.BarChart.Refresh(); // Start sorting _task = new Thread(() => algoConfig.SortingAlgorithm.Sort(algoConfig.Array)); _task.Start(); }
public void Visualize( AlgoConfig algoConfig ) { _algoConfig = algoConfig; algoConfig.SortingAlgorithm.ItemsCompared += SortingAlgorithm_ItemsCompared; algoConfig.SortingAlgorithm.ItemsSwaped += SortingAlgorythm_ItemsSwaped; algoConfig.SortingAlgorithm.ItemCopied += SortingAlgorythm_ItemCopied; algoConfig.SortingAlgorithm.Finished += SortingAlgorithm_Finished; // Update the Ui this.Parent.Text = algoConfig.SortingAlgorithm.Name; this.HowItWorksTextBox.Text = algoConfig.SortingAlgorithm.HowItWorks; this.LabelN.Text = string.Format( "{0}", algoConfig.Array.Length ); // Show the initial array _values = algoConfig.Array; _compares = 0; _swaps = 0; _copies = 0; LabelCompares.Text = string.Empty; LabelSwaps.Text = string.Empty; LabelCopies.Text = string.Empty; LabelBigO.Text = string.Empty; LabelTotalOperations.Text = string.Empty; _isPause = false; _autoBlockAfterOneOperation = false; _manualResetEvent.Set(); if( _task != null ) { _task.Abort(); } this.BarChart.GraphPane.CurveList.Clear(); this.BarChart.GraphPane.GraphObjList.Clear(); PointPairList list = new PointPairList(); Random rand = new Random(); for( int i = 0; i < _values.Length; i++ ) { list.Add( i, _values[ i ], 0 ); } BarItem myCurve = this.BarChart.GraphPane.AddBar( string.Empty, list, Color.Black ); // 0 1 2 3 4 myCurve.Bar.Fill = new Fill( new Color[] { Color.Black, Color.Red, Color.Yellow, Color.Blue } );// , Color.Green myCurve.Bar.Fill.Type = FillType.GradientByZ; myCurve.Bar.Fill.RangeMin = 0; myCurve.Bar.Fill.RangeMax = 3; this.BarChart.GraphPane.AxisChange(); this.BarChart.Refresh(); // Start sorting _task = new Thread( () => algoConfig.SortingAlgorithm.Sort( algoConfig.Array ) ); _task.Start(); }