共回答了21个问题采纳率:81%
将操作数作为二叉树的叶子结点,操作符作为二叉树的非叶子结点
先序遍历则得到前缀式
中序遍历则得到中缀式
后序遍历则得到后缀式
//以(a+b)/c-d+e*f进行演示
+
(- *)
(/ d) (e f)
(+ c)
(a b)
#include
#include
typedef char Elem;
typedef struct Node
{
Elem data;
struct Node *pLchild;
x09struct Node *pRchild;
}BTreeNode, *BTree;
BTree CreateBTree(BTree T, Elem *str)//创建二叉树
{
x09static int i = 0;
x09if ('0' == str[i])
x09{
x09x09T = NULL;
x09}
x09else
x09{
x09x09T = (BTree) malloc (sizeof(BTreeNode));
x09x09T->data = str[i++];
x09x09T->pLchild = CreateBTree(T->pLchild, str);
x09x09i++;
x09x09T->pRchild &