Beispiel #1
0
        public string Postfix2Prefix(string expression)
        {
            if (!CheckPostfix(expression))
            {
                Steps.Add(new Step("", "Revers"));
                return("");
            }
            Infiks infiks = new Infiks(Steps);

            expression = infiks.Postfiks2Infiks(expression);
            return(Infiks2Prefiks(expression));
        }
Beispiel #2
0
        private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Steps.Clear();
                Infiks   infiks   = new Infiks(Steps);
                Prefiks  prefiks  = new Prefiks(Steps);
                Postfiks postfiks = new Postfiks(Steps);

                if (Check(Expression.Text.ToString()))
                {
                    if (BaseInfix.IsChecked == true)
                    {
                        if (!infiks.CheckInfix(Expression.Text.ToString()))
                        {
                            this.ShowMessageAsync("Error", "Incorrect infix structure");
                        }
                        else
                        {
                            if (GoalInfix.IsChecked == true)
                            {
                                Steps.Add(new Step(Expression.Text.ToString(), ""));
                                this.ShowMessageAsync("Info", "Base and Goal are the same");
                            }
                            else if (GoalPostfix.IsChecked == true)
                            {
                                postfiks.Infiks2Postfiks(Expression.Text.ToString());
                            }
                            else if (GoalPrefix.IsChecked == true)
                            {
                                prefiks.Infiks2Prefiks(Expression.Text.ToString());
                            }
                            else
                            {
                                this.ShowMessageAsync("Error", "Base and Goal error");
                            }
                        }
                    }

                    if (BasePostfix.IsChecked == true)
                    {
                        if (!prefiks.CheckPostfix(Expression.Text.ToString()))
                        {
                            this.ShowMessageAsync("Error", "Incorrect postfix structure");
                        }
                        else
                        {
                            if (GoalInfix.IsChecked == true)
                            {
                                infiks.Postfiks2Infiks(Expression.Text.ToString());
                            }
                            else if (GoalPostfix.IsChecked == true)
                            {
                                Steps.Add(new Step(Expression.Text.ToString(), ""));
                                this.ShowMessageAsync("Info", "Base and Goal are the same");
                            }
                            else if (GoalPrefix.IsChecked == true)
                            {
                                prefiks.Postfix2Prefix(Expression.Text.ToString());
                            }
                            else
                            {
                                this.ShowMessageAsync("Error", "Base and Goal error");
                            }
                        }
                    }

                    if (BasePrefix.IsChecked == true)
                    {
                        if (!prefiks.CheckPrefix(Expression.Text.ToString()))
                        {
                            this.ShowMessageAsync("Error", "Incorrect prefix structure");
                        }
                        else
                        {
                            if (GoalInfix.IsChecked == true)
                            {
                                infiks.Prefiks2Infiks(Expression.Text.ToString());
                            }
                            else if (GoalPostfix.IsChecked == true)
                            {
                                postfiks.Prefisk2Postfix(Expression.Text.ToString());
                            }
                            else if (GoalPrefix.IsChecked == true)
                            {
                                Steps.Add(new Step(Expression.Text.ToString(), ""));
                                this.ShowMessageAsync("Info", "Base and Goal are the same");
                            }
                            else
                            {
                                this.ShowMessageAsync("Error", "Base and Goal error");
                            }
                        }
                    }
                }
                else
                {
                    this.ShowMessageAsync("Info", "Incorrect arithmetic expression");
                }
                StepsListView.Items.Refresh();
            }
        }