Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


How to store the parsed data of the expression from a file to construct an expression tree


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 warnexus   Prime Members   -  Reputation: 1504

Like
0Likes
Like

Posted 30 April 2013 - 08:00 AM

This is one expression from the first line of the file. 

 

- + + 4.0 - / - 22.0 2.0 5.0 * 3.0 4.0 7.0 / 6.0 3.0

 

The problem lies I do not understand where do these operands and numbers get stored to construct a expression tree during the time the above expression gets parsed. After constructing an expression tree, the tree is suppose to be able to output  preorder,inorder and postorder expression of that tree.

 

From the example given, the operands are connected by an operator, but the example does not help guide me in terms of how to lay the operands and numbers out for this expression.

 

I tried using a stack diagram to visualize the design of my program better but I am stuck when 22.0 appears on the stack. What is suppose to happen when 22.0 appears on the stack?

 

stack_zps213b2cb1.png


Edited by warnexus, 30 April 2013 - 08:31 AM.


Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5440

Like
0Likes
Like

Posted 30 April 2013 - 09:23 AM

List looks backwards to me? Try pushing values from the right hand side of the list onto the stack and replace the top 2 elements with the result of the operation when you push an operator?

 

so 3.0 6.0 / => pushes 3, 6 and then replaces them with 3.0 / 6.0 = 0.5 when the division operator is pushed.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 warnexus   Prime Members   -  Reputation: 1504

Like
0Likes
Like

Posted 30 April 2013 - 10:32 AM

List looks backwards to me? Try pushing values from the right hand side of the list onto the stack and replace the top 2 elements with the result of the operation when you push an operator?

 

so 3.0 6.0 / => pushes 3, 6 and then replaces them with 3.0 / 6.0 = 0.5 when the division operator is pushed.

reversing the list was the perfect strategy to evaluating the expression. Thanks Paradigm.


Edited by warnexus, 30 April 2013 - 10:58 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS