Member Avatar for soUPERMan

Hello,

I wanna write a method that recieves an argument of type String which is a mathematical expression in infix mode, then change it to postfix and store in a queue and return the queue...how do i go about that?? I have created so far a Queue class, Node class.

Recommended Answers

All 4 Replies

Member Avatar for soUPERMan

Thanks quuba, one more question though...if i want to use a queue, must i only use it with something like a linkedlist or such similes??

All ways are allowed.
Look at http://en.wikipedia.org/wiki/Reverse_Polish_notation

Converting from infix notation
Main article: Shunting-yard algorithm

Edsger Dijkstra invented the Shunting-yard algorithm to convert infix expressions to postfix (RPN), so named because its operation resembles that of a railroad shunting yard.

There are other ways of producing postfix expressions from infix notation. Most Operator-precedence parsers can be modified to produce postfix expressions; in particular, once an abstract syntax tree has been constructed, the corresponding postfix expression is given by a simple post-order traversal of that tree.

See:http://en.wikipedia.org/wiki/Tree_traversal

Traversal
Compared to linear data structures like linked lists and one dimensional arrays, which have only one logical means of traversal, tree structures can be traversed in many different ways.

Possible ways of passing binary tree:

There are 6 ways:
VLR - pre-order (Ɓukasiewicz),
LVR - in-order,
LRV - post-order (RPN),
VRL,
RVL,
RLV,

where :
V - Visit node,
L - go Left,
R - goRight.
It is interesting to see mathematical expressions in all six ways.
-but, why I have not yet done - it's a question!
----------------------
for the question - I can't give a respond - it all depends on the implementation details

[can you give the code to convert infix to postfix expression]
lucky_username

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.