nguyenvanquan7826

Untitled

Jul 9th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. private void ProcessPostfix(Control ctl)
  2.         {
  3.             if (ExprHelper.IsOperator(ctl.Text))
  4.             {
  5.  
  6.                 if (_preCtl != null && ExprHelper.IsOperator(_preCtl.Text))
  7.                 {
  8.                     if (ctl.Text == "-")
  9.                     {
  10.                         _nextCtl.Text = ctl.Text   _nextCtl.Text;
  11.                         Output(_nextCtl);
  12.                     }
  13.                     else if (ExprHelper.IsUnaryFunction(ctl.Text))
  14.                     {
  15.                         PushStack(ctl);
  16.                     }
  17.                 }
  18.                 else
  19.                 {
  20.                     while (pnlStack.Controls.Count > 0 &&
  21.                         ExprHelper.GetPriority(ctl.Text) <= ExprHelper.GetPriority(PeekStack().Text))
  22.                         Output(PopStack());
  23.                     PushStack(ctl);
  24.                 }
  25.             }
  26.  
  27.             else if (ctl.Text == "(")
  28.                 PushStack(ctl);
  29.             else if (ctl.Text == ")")
  30.             {
  31.                 Control x = PopStack();
  32.                 while (x.Text != "(")
  33.                 {
  34.                     Output(x);
  35.                     x = PopStack();
  36.                 }
  37.             }
  38.             else // IsOperand
  39.             {
  40.                 Output(ctl);
  41.             }
  42.  
  43.         }
  44.  
  45.         Control PeekStack()
  46.         {
  47.             return pnlStack.Controls[pnlStack.Controls.Count - 1];
  48.         }
  49.         Control PopStack()
  50.         {
  51.             Control ctl = pnlStack.Controls[pnlStack.Controls.Count - 1];
  52.             pnlStack.Controls.Remove(ctl);
  53.  
  54.             return ctl;
  55.         }
  56.         void PushStack(Control ctl)
  57.         {
  58.             pnlStack.Controls.Add(ctl);
  59.  
  60.             if (pnlStack.Controls.Count > 1)
  61.                 pnlStack.Controls[pnlStack.Controls.Count - 2].BackgroundImage = _imgNormal;
  62.         }
  63.         void Output(Control ctl)
  64.         {
  65.             pnlOutput.Controls.Add(ctl);
  66.  
  67.             if (pnlOutput.Controls.Count > 1)
  68.                 pnlOutput.Controls[pnlOutput.Controls.Count - 2].BackgroundImage = _imgNormal;
  69.         }
Advertisement
Add Comment
Please, Sign In to add comment