50字范文,内容丰富有趣,生活中的好帮手!
50字范文 > java前缀表达式二叉树课程设计_表达式构建二叉树(中缀 前缀 后缀)

java前缀表达式二叉树课程设计_表达式构建二叉树(中缀 前缀 后缀)

时间:2023-10-16 02:47:09

相关推荐

java前缀表达式二叉树课程设计_表达式构建二叉树(中缀 前缀 后缀)

// TheRealBinaryTreeOfMine.cpp : 定义控制台应用程序的入口点。

//

#include"stdafx.h"

#include

#include

#include

#include

#include

using namespace std;

class BinaryNode{

public:

char date;

BinaryNode * leftchild;

BinaryNode * rightchild;

BinaryNode(){

date = 0;

leftchild = NULL;

rightchild = NULL;

}

BinaryNode(char ch){

date = ch;

leftchild = NULL;

rightchild = NULL;

}

};

int first_or_last(char a, char b); //判断两个运算符的优先级;

bool isOP(char ch); //判断该字符是否属于操作符;BinaryNode* Build_BinaryTree(BinaryNode* &BT, string str);//根据中缀表达式构建一颗二叉树;

void Last(BinaryNode *bt); //后序遍历二叉树(递归);

void First(BinaryNode *bt); //先序遍历二叉树(递归);

void Inn(BinaryNode *bt); //中序遍历二叉树(递归);

string Exp_turn(string s); //后缀表达式转换成中缀表达式;

string Exp_turn_and_turn(string s); //前缀表达式转换为中缀表达式;

int choice(char c, char d); //判断表达式属于什么类型的表达式(中缀,后缀,前缀);

void Print(BinaryNode *bt); //打印二叉树(层序遍历,层层打印二叉树);int first_or_last(char a, char b){

if (a == '/' || a == '*'){

if (b == '+' || b == '-')

return 1;

if (b == '/' || b == '*')

return 0;

else

return 0;

}

if (a == '+' || a == '-'){

if (b == '+' || b == '-')

return 0;

if (b == '/' || b == '*')

return 0;

else

return 0;

}

else

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。