Example #1
0
        public string Infiks2Prefiks(string expression)
        {
            char[] arr = expression.ToCharArray();
            Array.Reverse(arr);
            string temp    = new string(arr);
            string newtemp = "";

            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i] == '(')
                {
                    newtemp += ')';
                }
                else if (temp[i] == ')')
                {
                    newtemp += '(';
                }
                else
                {
                    newtemp += temp.ElementAt(i);
                }
            }
            Steps.Add(new Step(newtemp, "Revers"));
            Postfiks postfiks = new Postfiks(Steps);
            string   result   = postfiks.Infiks2Postfiks(newtemp);

            char[] arr1 = result.ToCharArray();
            Array.Reverse(arr1);
            string ReversResult = new string(arr1);

            Steps.Add(new Step(ReversResult, "Revers"));
            return(ReversResult);
        }
Example #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();
            }
        }