infix.cpp

来自「这是数据结构、算法与应用-C++语言描述的代码」· C++ 代码 · 共 30 行

CPP
30
字号
// generate infix from expression tree

#include <iostream>
#include "binaryTreeNode.h"

using namespace std;

template <class T>
void infix(binaryTreeNode<T> *t)
{// Output infix form of expression.
   if (t != NULL)
   {
      cout << '(';
      infix(t->leftChild);   // left operand
      cout << t->element;    // operator
      infix(t->rightChild);  // right operand
      cout << ')';
   }
}

int main(void)
{
   binaryTreeNode<int> x,y,z;
   x.element = 1; y.element = 2; z.element = 3;
   x.leftChild = &y; x.rightChild = &z;
   y.leftChild = y.rightChild = z.leftChild = z.rightChild = 0;
   infix(&x);
   cout << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?