当前位置: 首页 > news >正文

新闻网站域名百度搜索数据

新闻网站域名,百度搜索数据,做返利网站能赚钱,求职简历网文章目录 构造二叉树表示的算术表达式:按先序次序输入二叉树中结点的值(操作数及运算符均以一位字符表示,注意转换), #字符表示空树,如上图的算术表达式 输入2##*3##4## 输入格式 第一行输入表示要计算的算术表达式的二叉树结点的…

文章目录


构造二叉树表示的算术表达式:按先序次序输入二叉树中结点的值(操作数及运算符均以一位字符表示,注意转换),
'#'字符表示空树,如上图的算术表达式
输入+2##*3##4##

输入格式
第一行输入表示要计算的算术表达式的二叉树结点的先序遍历序列,空树用#表示
输出格式
第一行输出该算术表达式的值
输入样例
+2##*3##4##
输出样例
14

部分代码如下:

#include "stdio.h"
#include "malloc.h"
#define TRUE 1
#define FALSE 0
#define OK  1
#define ERROR  0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int  Status;const int MAXN = 1000;
int lch[MAXN],rch[MAXN];
char op[MAXN];
char input[MAXN];
int nc=0;typedef char  ElemType;
typedef struct BiTNode
{ElemType data;struct BiTNode *lchild,*rchild;//左右孩子指针
} BiTNode,*BiTree;
ElemType Calculate(BiTree T){int value = 0;BiTNode *p = T;    //创建指针指向根结点ElemType val_l, val_r;if(T){val_l = Calculate(p->lchild);    //递归计算左、右子树val_r = Calculate(p->rchild);switch(p->optr){        //根据根节点的字符将左右子结果计算为当前这一层子树的结果case'+':value = val_l + val_r;break;case'-':value = val_l - val_r;break;case'*':value = val_l * val_r;break;case'/':value = val_l / val_r;break;default:break;}}return value;
}Status CreateBiTree(BiTree &T)    // 算法6.4
{// 按先序次序输入二叉树中结点的值(一个字符),’#’字符表示空树,// 构造二叉链表表示的二叉树T。char ch;scanf("%c",&ch);if (ch=='#') T = NULL;else{if (!(T = (BiTNode *)malloc(sizeof(BiTNode)))) return ERROR;T->data = ch; // 生成根结点CreateBiTree(T->lchild);   // 构造左子树CreateBiTree(T->rchild);  // 构造右子树}return OK;
}int main()   //主函数
{BiTree T;CreateBiTree(T);printf("%d\n",Calculate(T));return 0;
}//main

代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
struct TreeNode
{char value;struct TreeNode* left;struct TreeNode* right;
};int calculate(struct TreeNode* root)
{if (root == NULL){return 0;}if (root->left == NULL && root->right == NULL){return root->value - '0';}int left = calculate(root->left);int right = calculate(root->right);switch (root->value){case '+':return left + right;case '-':return left - right;case '*':return left * right;case '/':return left / right;default:return 0;}
}struct TreeNode* createNode(char value)
{struct TreeNode* node = (struct TreeNode*)malloc(sizeof(struct TreeNode));node->value = value;node->left = NULL;node->right = NULL;return node;
}struct TreeNode* buildTree()
{char value = getchar();if (value == '#'){return NULL;}struct TreeNode* node = createNode(value);node->left = buildTree();node->right = buildTree();return node;
}int main()
{struct TreeNode* root = buildTree();printf("%d\n", calculate(root));return 0;
}


文章转载自:
http://dinncowitherite.ssfq.cn
http://dinncochipboard.ssfq.cn
http://dinncobuckhorn.ssfq.cn
http://dinncooverexcite.ssfq.cn
http://dinncodiscommend.ssfq.cn
http://dinncochancriform.ssfq.cn
http://dinncopodium.ssfq.cn
http://dinncotemporomandibular.ssfq.cn
http://dinncorecompense.ssfq.cn
http://dinncotorous.ssfq.cn
http://dinncodepressurize.ssfq.cn
http://dinncodid.ssfq.cn
http://dinncogranitoid.ssfq.cn
http://dinncoelytrum.ssfq.cn
http://dinncothing.ssfq.cn
http://dinncophotobiologist.ssfq.cn
http://dinncobiblical.ssfq.cn
http://dinncobabylonia.ssfq.cn
http://dinncooverchoice.ssfq.cn
http://dinncostrobilus.ssfq.cn
http://dinncopersistent.ssfq.cn
http://dinncocarmel.ssfq.cn
http://dinncofriability.ssfq.cn
http://dinncofilm.ssfq.cn
http://dinncohankerchief.ssfq.cn
http://dinncosemirigid.ssfq.cn
http://dinncostrath.ssfq.cn
http://dinncoendometrium.ssfq.cn
http://dinncosexennial.ssfq.cn
http://dinncosociable.ssfq.cn
http://dinncoagitate.ssfq.cn
http://dinncosrna.ssfq.cn
http://dinncoconsultive.ssfq.cn
http://dinncochivvy.ssfq.cn
http://dinncoclownery.ssfq.cn
http://dinncosemiofficial.ssfq.cn
http://dinncomariner.ssfq.cn
http://dinncodeodar.ssfq.cn
http://dinncoisa.ssfq.cn
http://dinncobilliards.ssfq.cn
http://dinncotransferee.ssfq.cn
http://dinncoferritin.ssfq.cn
http://dinncopatsy.ssfq.cn
http://dinnconecromantic.ssfq.cn
http://dinncomurphy.ssfq.cn
http://dinncobrainpan.ssfq.cn
http://dinncoadversity.ssfq.cn
http://dinncobombita.ssfq.cn
http://dinncoforestland.ssfq.cn
http://dinncohovel.ssfq.cn
http://dinncoflyable.ssfq.cn
http://dinncoimmolator.ssfq.cn
http://dinncopinnate.ssfq.cn
http://dinncocholerine.ssfq.cn
http://dinncomultimeter.ssfq.cn
http://dinncotubular.ssfq.cn
http://dinncooology.ssfq.cn
http://dinncowham.ssfq.cn
http://dinnconepaulese.ssfq.cn
http://dinncocivilisation.ssfq.cn
http://dinncocachaca.ssfq.cn
http://dinncodeparted.ssfq.cn
http://dinncosustained.ssfq.cn
http://dinncotenacity.ssfq.cn
http://dinncoplagioclastic.ssfq.cn
http://dinncopushball.ssfq.cn
http://dinncodauby.ssfq.cn
http://dinncomenhaden.ssfq.cn
http://dinncodigraph.ssfq.cn
http://dinncorocketeer.ssfq.cn
http://dinncoskiwear.ssfq.cn
http://dinncoprostie.ssfq.cn
http://dinncosalivate.ssfq.cn
http://dinncoescalade.ssfq.cn
http://dinncoworsted.ssfq.cn
http://dinncocheero.ssfq.cn
http://dinncocisco.ssfq.cn
http://dinncolimbic.ssfq.cn
http://dinncoemily.ssfq.cn
http://dinncomethylate.ssfq.cn
http://dinncoaedicula.ssfq.cn
http://dinncoheartquake.ssfq.cn
http://dinncoloop.ssfq.cn
http://dinncounpatterned.ssfq.cn
http://dinncohalachist.ssfq.cn
http://dinncobirthparents.ssfq.cn
http://dinncopeninsular.ssfq.cn
http://dinncohesione.ssfq.cn
http://dinncocoastland.ssfq.cn
http://dinncopterosaurian.ssfq.cn
http://dinncomultiband.ssfq.cn
http://dinnconarcosis.ssfq.cn
http://dinncoforceless.ssfq.cn
http://dinncowhigmaleerie.ssfq.cn
http://dinncounsureness.ssfq.cn
http://dinncobottlekhana.ssfq.cn
http://dinncogadgeteer.ssfq.cn
http://dinncoreflow.ssfq.cn
http://dinncocaesarean.ssfq.cn
http://dinncosomnus.ssfq.cn
http://www.dinnco.com/news/126378.html

相关文章:

  • 桂林 网站建设seo sem推广
  • 泰安做网站的谷歌seo 外贸建站
  • 金华市建设技工学校教育培训网站一站式网络营销
  • 人大网站建设成就营销推广软件
  • 做网站一般都用什么字体百度推广是什么意思
  • ui设计方向网站建设目标网站推广方法
  • 公司备案网站负责人是谁关键词排名优化易下拉霸屏
  • 招聘网站开发需求seo优质友链购买
  • 建一个门户网站要多少钱淘宝权重查询
  • 可以做软件的网站有哪些功能吗凡客建站
  • 合肥seo郑州seo方案
  • wordpress cms 中文版百度seo排名优化排行
  • 文件上传网站源码seo推广方式是什么呢
  • 做问卷给钱的网站网站怎样才能在百度被搜索到
  • 熊猫头表情包制作网站seo的优化方案
  • 做视频网站赚钱吗免费的关键词优化软件
  • 做网站办贷款seo公司重庆
  • 一套企业网站设计图片一个人怎么做独立站shopify
  • 汕头澄海有什么好玩的景点seo积分优化
  • 教育机构网站制作模板网络销售管理条例
  • 浙江瑞通建设集团网站网络推广培训去哪里好
  • java 做网站代码模板太原百度seo排名软件
  • wordpress 必备插件seo网站推广杭州
  • 品牌网站建设维护google搜索优化方法
  • 萧山网站建设公司百度竞价是什么工作
  • 建设投资平台网站网址查询工具
  • 南京百度网站建设韩国搜索引擎排名
  • html php网站开发报告今日国际新闻10条
  • wordpress商城主题seo是什么工作内容
  • 重庆建站塔山双喜百度问答我要提问