2 Replies - 15524 Views - Last Post: 19 September 2009 - 07:56 AM Rate Topic: -----

#1 procyon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-September 09

Converting postfix, infix, prefix and binary trees in one program

Post icon  Posted 19 September 2009 - 07:39 AM

procyon 


PLease help me in my assignment.... HUHUHU i need that to pass in my subject Data Structure and Algorithm..... Please I need that by Monday....

Coverting Postfix,Prefix,Infix and Binary trees in one program.
Is This A Good Question/Topic? 0
  • +

Replies To: Converting postfix, infix, prefix and binary trees in one program

#2 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Converting postfix, infix, prefix and binary trees in one program

Posted 19 September 2009 - 07:44 AM

You should read the rules of the forum #1 in particular xD
Was This Post Helpful? 0
  • +
  • -

#3 Darkhack  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 208
  • Joined: 25-November 08

Re: Converting postfix, infix, prefix and binary trees in one program

Posted 19 September 2009 - 07:56 AM

Do you have any code already written? All I see is your username in your code tags.

You don't provide a detailed explanation for what you what, but it sounds like you want to use a binary tree structure to store an equation and then convert it between prefix, infix, and postfix forms. Is this right?

A binary tree is a tree data structure that has, at most, two children. It could also have just one or zero children. This is usually implemented with a struct that has data for the value stored at that node, and pointers to the child nodes. To store an equation in a tree, you will store the operator (+ - * /) in the parent and the two children will be the operands.

struct Node
{
	char val;
	Node *left;
	Node *right;
};



A simple equation might look like this

		   *
	+		   3
 2	 5



To get the different forms you simply traverse the tree in different orders.

Prefix: (* (+ 2 5) 3)

1. Return value from node.
2. Traverse Left.
3. Traverse Right.

Infix: ((2 + 5) * 3)

1. Traverse left.
2. Return value from node.
3. Traverse right.

Postfix: ((2 5 +) 3 *)

1. Traverse left.
2. Traverse right.
3. Return value from node.

More information: http://en.wikipedia..../Tree_traversal
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1