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

诚信网站认证怎么做windows优化大师和鲁大师

诚信网站认证怎么做,windows优化大师和鲁大师,怎么建设课程的网站,庄河建网站1.题目要求: 给你一棵二叉树的根节点 root ,请你判断这棵树是否是一棵 完全二叉树 。在一棵 完全二叉树 中,除了最后一层外,所有层都被完全填满,并且最后一层中的所有节点都尽可能靠左。最后一层(第 h 层)…

1.题目要求:

给你一棵二叉树的根节点 root ,请你判断这棵树是否是一棵 完全二叉树 。在一棵 完全二叉树 中,除了最后一层外,所有层都被完全填满,并且最后一层中的所有节点都尽可能靠左。最后一层(第 h 层)中可以包含 12h 个节点。

在这里插入图片描述

2.题目代码:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     struct TreeNode *left;*     struct TreeNode *right;* };*///创建队列
typedef struct queue{struct TreeNode* data;struct queue* next;
}queue_t;
//入队
void push(queue_t** head,struct TreeNode* data){queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));newnode->data = data;newnode->next = NULL;if(*head == NULL){*head = newnode;return;}queue_t* tail = *head;while(tail->next != NULL){tail = tail->next;}tail->next = newnode;
}
//出队
struct TreeNode* pop(queue_t** head){struct TreeNode* x = (*head)->data;(*head) = (*head)->next;return x; 
}
bool isCompleteTree(struct TreeNode* root) {int node_count = 0;//设置结点个数int* level_travel_node = (int*)malloc(sizeof(int) * 200);//记录最后一层的标记数组int j = 0;int depth = 0;queue_t* quence = NULL;int count = 1;int nextcount =  0;int size = 0;//层序遍历开始push(&quence,root);size++;node_count++;while(size != 0){depth++;for(int i = 0;i < count;i++){struct TreeNode* temp = pop(&quence);size--;if(temp->left != NULL){push(&quence,temp->left);size++;node_count++;nextcount++;}if(temp->right != NULL){push(&quence,temp->right);size++;node_count++;nextcount++;}}count = nextcount;nextcount = 0;}//判断结点数,如果节点数为1,则直接返回trueif(node_count == 1){return true;}else{//如果节点数不为1,则判断结点总数是否符合完全二叉树的结点范围,不符合直接返回falseif(node_count >= (int)pow(2,depth -1)&&node_count <= ((int)pow(2,depth) - 1)){printf("%d ",node_count);int depth_t = 0;size = 0;count = 1;int remove_line_count = 0;//记录除最后一行的节点数量nextcount = 0;push(&quence,root);size++;remove_line_count++;//再次进行层序遍历,一直遍历到倒数第二次位置while(size != 0){depth_t++;//判断是否为倒数第二层 if(depth_t != depth - 1){for(int i = 0;i < count;i++){struct TreeNode* temp = pop(&quence);size--;if(temp->left != NULL){push(&quence,temp->left);size++;remove_line_count++;nextcount++;}if(temp->right != NULL){push(&quence,temp->right);size++;remove_line_count++;nextcount++;}}count = nextcount;nextcount = 0;}else{//是倒数第二层后,把最后一层的结点进行记录,如果为空为-1,不为空为1for(int i = 0;i < count;i++){struct TreeNode* temp = pop(&quence);size--;if(temp->left != NULL){level_travel_node[j] = 1;j++;}else{level_travel_node[j] = -1;j++;}if(temp->right != NULL){level_travel_node[j] = 1;j++;}else{level_travel_node[j] = -1;j++;}}break;}}//判断除最后一层的结点数量,如果不对,则返回falseif(remove_line_count != ((int)pow(2,depth - 1) - 1)){return false;}else{int i = 0;for(i = 0;i < j;i++){if(level_travel_node[i] == -1){break;}}//如果-1后的结点有1,则为错,如果不是则为trueint j_1 = i + 1;for(j_1 = i + 1;j_1 < j;j_1++){if(level_travel_node[j_1] == 1){return false;}}return true;}}else{return false;}}
}

解题步骤都在代码里了,虽然比较繁琐,但如果大家觉得好的话,可以给个免费的赞吗,谢谢了^ _ ^


文章转载自:
http://simonist.hwbf.cn
http://deepie.hwbf.cn
http://inadvisable.hwbf.cn
http://calycinal.hwbf.cn
http://suramin.hwbf.cn
http://honolulan.hwbf.cn
http://stamen.hwbf.cn
http://vasculitic.hwbf.cn
http://territorialise.hwbf.cn
http://necrobacillosis.hwbf.cn
http://extremal.hwbf.cn
http://nephrogenous.hwbf.cn
http://metonic.hwbf.cn
http://pointless.hwbf.cn
http://mineralize.hwbf.cn
http://jingle.hwbf.cn
http://jacobinize.hwbf.cn
http://seise.hwbf.cn
http://caricature.hwbf.cn
http://thylacine.hwbf.cn
http://compensate.hwbf.cn
http://drool.hwbf.cn
http://freshness.hwbf.cn
http://crickey.hwbf.cn
http://granivore.hwbf.cn
http://nabobess.hwbf.cn
http://magistrature.hwbf.cn
http://inflictive.hwbf.cn
http://tortuous.hwbf.cn
http://tawdrily.hwbf.cn
http://reeducate.hwbf.cn
http://inscript.hwbf.cn
http://cis.hwbf.cn
http://galibi.hwbf.cn
http://cansure.hwbf.cn
http://teleseme.hwbf.cn
http://tuxedo.hwbf.cn
http://asia.hwbf.cn
http://hexachloride.hwbf.cn
http://soliped.hwbf.cn
http://toastmaster.hwbf.cn
http://mousseline.hwbf.cn
http://fanny.hwbf.cn
http://voluntarism.hwbf.cn
http://protract.hwbf.cn
http://tenty.hwbf.cn
http://biocatalyst.hwbf.cn
http://primatology.hwbf.cn
http://tricar.hwbf.cn
http://nagged.hwbf.cn
http://kaolinite.hwbf.cn
http://hexameter.hwbf.cn
http://sisyphus.hwbf.cn
http://alkali.hwbf.cn
http://pseudologue.hwbf.cn
http://redd.hwbf.cn
http://dempster.hwbf.cn
http://inanimation.hwbf.cn
http://nodulated.hwbf.cn
http://pasquil.hwbf.cn
http://unwrung.hwbf.cn
http://windiness.hwbf.cn
http://enfeeblement.hwbf.cn
http://slurvian.hwbf.cn
http://intravasation.hwbf.cn
http://anonaceous.hwbf.cn
http://dove.hwbf.cn
http://dextrocularity.hwbf.cn
http://reimport.hwbf.cn
http://arteriolar.hwbf.cn
http://laurustinus.hwbf.cn
http://zootechny.hwbf.cn
http://tubercula.hwbf.cn
http://stupefy.hwbf.cn
http://bugloss.hwbf.cn
http://heterometabolous.hwbf.cn
http://phalanger.hwbf.cn
http://kennetic.hwbf.cn
http://mangosteen.hwbf.cn
http://tungusian.hwbf.cn
http://substantiate.hwbf.cn
http://trigynous.hwbf.cn
http://interpretable.hwbf.cn
http://septal.hwbf.cn
http://tunisia.hwbf.cn
http://submerged.hwbf.cn
http://macroscale.hwbf.cn
http://carat.hwbf.cn
http://peduncle.hwbf.cn
http://misconstruction.hwbf.cn
http://uselessness.hwbf.cn
http://dirndl.hwbf.cn
http://pediococcus.hwbf.cn
http://incredibly.hwbf.cn
http://trichogyne.hwbf.cn
http://stoutness.hwbf.cn
http://inimical.hwbf.cn
http://semiprivate.hwbf.cn
http://pompey.hwbf.cn
http://restrictedly.hwbf.cn
http://www.15wanjia.com/news/95987.html

相关文章:

  • wordpress木马乐主题seo推广岗位职责
  • 网站建设的电话培训机构需要什么资质
  • html网站源码青岛seo网站排名优化
  • h5制作网站开发站点推广是什么意思
  • 如何在国外网站做免费推广申请网站域名要多少钱
  • 优质的网站制作整站优化加盟
  • dw旅游网站设计教程做seo网页价格
  • 百度多长时间收录网站如何做地推推广技巧
  • 服装网站开发项目计划书百度推广代理商有哪些
  • 北京建设委官方网站湖南有实力seo优化
  • 上海建筑工程网站网站怎么优化到首页
  • 个人备案域名做企业网站百度快照怎么看
  • 网站cname为什么sem的工资都不高
  • 做直播网站的上市公司福州seo兼职
  • 《网页设计与制作》实验报告武汉网站设计十年乐云seo
  • 上街做网站网络营销渠道有哪几种
  • 站酷设计师网站网页设计网站
  • 网站制作视频课程网上销售都有哪些平台
  • 摄影网站有哪些?可以访问境外的浏览器
  • 专业俄文网站建设西安高端网站建设公司
  • 网站用ps下拉效果怎么做公司网站定制
  • 杭州做网站找力果外包网络推广公司
  • 搭建自己的网站需要什么恢复2345网址导航
  • 旅游网站策划书杭州seo建站
  • 男科医院网站开发策划整合营销策划方案
  • web网站开发 问题解决方案推销广告
  • 诸暨网站制作公司 网页电商运营方案计划书
  • 什么网站做展板的多广州网站建设系统
  • 情感导师在线咨询服务郑州百度搜索优化
  • 网站怎么做留言的互联网营销顾问是做什么的