《数据结构与算法》上的一道作业题答案,本程序设计二叉树的构建,遍历以及打印等函数,能够实现自动分辨所输入表达式属于什么类型。
bNum.pop();
g++;
if (!bOP.empty()){
ss[g] = bOP.front();
bOP.pop();
g++;
}
}
ss[g] = '\0';
return ss;
} //实现了前缀表达式转换为中缀表达式; void Print(BinaryNode *bt){
cout << endl << endl;
queue<BinaryNode*> qQ;
char strstr[30];
int t = 0;
if (bt){
qQ.push(bt);
}
while (!qQ.empty()){
bt = qQ.front();
strstr[t] = bt->date;
t++;
qQ.pop();
if (bt->leftchild != NULL)
qQ.push(bt->leftchild);
if (bt->rightchild != NULL)
qQ.push(bt->rightchild);
}
录在一个数组当中,元素个数为t个
strstr[t] = '\0';
int x = 10, y = 5;;
for (int m = 0; m < x; m++){
cout << ' ';
}
cout << strstr[0] << endl;
int e = 1;
for (int n = 0; n < log2(t + 1); n++){
for (int v = 0; v < x - y; v++){
cout << ' ';
}
cout << strstr[e];
e++;
int z = 0;
for (z = 0; z < 10; z++){
cout << ' ';
}
cout << strstr[e];
e++;
x = x + y;
cout << endl;
}
}
int choice(char c, char d){
if (isOP(c))
return 1;
if (!isOP(c) && !isOP(d)) //采用非递归的方法层序遍历二叉树,并将序列记//此处log2(t+1)是计算该二叉树的深度
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库表达式构建二叉树(中缀,前缀,后缀)(5)在线全文阅读。
相关推荐: