Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 97509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:01:07+00:00 2026-05-11T00:01:07+00:00

There are enough resources on how to convert an expression tree into postfix notation,

  • 0

There are enough resources on how to convert an expression tree into postfix notation, and it’s not that hard.

But I have to parse a postfix expression into an expression tree.

The expression is:

A 2 ^ 2 A * B * – B 2 ^ + A B – /

I don’t really have a clue on how to interpret the expression. Does someone has a clue on how to proces this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:01:08+00:00Added an answer on May 11, 2026 at 12:01 am

    Create a stack containing nodes that could be part of a tree

    1. Push operands on a stack (A, 2, B, etc. are operands) as leaf-nodes, not bound to any tree in any direction
    2. For operators, pop the necessary operands off the stack, create a node with the operator at the top, and the operands hanging below it, push the new node onto the stack

    For your data:

    1. Push A onto the stack
    2. Push 2 onto the stack
    3. Pop 2 and A, create ^-node (with A and 2 below), push it on the stack
    4. Push 2 on stack
    5. Push A on stack
    6. Pop A and 2 and combine to form the *-node
    7. etc.
    8. etc.

    tree structure

    Here is a LINQPad program that can be experimented with:

    // Add the following two using-directives to LINQPad: // System.Drawing // System.Drawing.Imaging  static Bitmap _Dummy = new Bitmap(16, 16, PixelFormat.Format24bppRgb); static Font _Font = new Font('Arial', 12);  void Main() {     var elementsAsString = 'A 2 ^ 2 A * B * - B 2 ^ + A B - / 2 ^';     var elements = elementsAsString.Split(' ');      var stack = new Stack<Node>();     foreach (var element in elements)         if (IsOperator(element))         {             Node rightOperand = stack.Pop();             Node leftOperand = stack.Pop();             stack.Push(new Node(element, leftOperand, rightOperand));         }         else             stack.Push(new Node(element));      Visualize(stack.Pop()); }  void Visualize(Node node) {     node.ToBitmap().Dump(); }  class Node {     public Node(string value)         : this(value, null, null)     {     }      public Node(string value, Node left, Node right)     {         Value = value;         Left = left;         Right = right;     }      public string Value;     public Node Left;     public Node Right;      public Bitmap ToBitmap()     {         Size valueSize;         using (Graphics g = Graphics.FromImage(_Dummy))         {             var tempSize = g.MeasureString(Value, _Font);             valueSize = new Size((int)tempSize.Width + 4, (int)tempSize.Height + 4);         }          Bitmap bitmap;         Color valueColor = Color.LightPink;         if (Left == null && Right == null)         {             bitmap = new Bitmap(valueSize.Width, valueSize.Height);             valueColor = Color.LightGreen;         }         else         {             using (var leftBitmap = Left.ToBitmap())             using (var rightBitmap = Right.ToBitmap())             {                 int subNodeHeight = Math.Max(leftBitmap.Height, rightBitmap.Height);                 bitmap = new Bitmap(                     leftBitmap.Width + rightBitmap.Width + valueSize.Width,                     valueSize.Height + 32 + subNodeHeight);                  using (var g = Graphics.FromImage(bitmap))                 {                     int baseY  = valueSize.Height + 32;                      int leftTop = baseY; // + (subNodeHeight - leftBitmap.Height) / 2;                     g.DrawImage(leftBitmap, 0, leftTop);                      int rightTop = baseY; // + (subNodeHeight - rightBitmap.Height) / 2;                     g.DrawImage(rightBitmap, bitmap.Width - rightBitmap.Width, rightTop);                      g.DrawLine(Pens.Black, bitmap.Width / 2 - 4, valueSize.Height, leftBitmap.Width / 2, leftTop);                     g.DrawLine(Pens.Black, bitmap.Width / 2 + 4, valueSize.Height, bitmap.Width - rightBitmap.Width / 2, rightTop);                 }             }         }          using (var g = Graphics.FromImage(bitmap))         {             float x = (bitmap.Width - valueSize.Width) / 2;             using (var b = new SolidBrush(valueColor))                 g.FillRectangle(b, x, 0, valueSize.Width - 1, valueSize.Height - 1);             g.DrawRectangle(Pens.Black, x, 0, valueSize.Width - 1, valueSize.Height - 1);             g.DrawString(Value, _Font, Brushes.Black, x + 1, 2);         }          return bitmap;     } }  bool IsOperator(string s) {     switch (s)     {         case '*':         case '/':         case '^':         case '+':         case '-':             return true;          default:             return false;     } } 

    Output:

    LINQPad output

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use NetBeans to design your GUI. Instead of… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer BinaryBlob should generate the proper VarBinary column for you. May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer Are you talking about line break? <br /> Also if… May 11, 2026 at 11:48 pm

Related Questions

I am developing a scientific application used to perform physical simulations. The algorithms used
I'm interested in precisely extracting portions of a PCM WAV file, down to the
There are quite a few resources for programmatically creating .lnk type shortcuts to files
As recently as several years ago, the developers actually made the builds that went

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.