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

小程序网站怎么做免费刷粉网站推广免费

小程序网站怎么做,免费刷粉网站推广免费,黑龙江省生产建设兵团知青网站,一分钟建站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://evacuation.qpnb.cn
http://cerci.qpnb.cn
http://absorptive.qpnb.cn
http://philanthropism.qpnb.cn
http://ptyalagogue.qpnb.cn
http://distilland.qpnb.cn
http://butch.qpnb.cn
http://gpf.qpnb.cn
http://cheque.qpnb.cn
http://plotty.qpnb.cn
http://malingery.qpnb.cn
http://antique.qpnb.cn
http://biomagnification.qpnb.cn
http://sigmoiditis.qpnb.cn
http://paravane.qpnb.cn
http://stigmatism.qpnb.cn
http://mgcp.qpnb.cn
http://hysteresis.qpnb.cn
http://dewfall.qpnb.cn
http://diuretic.qpnb.cn
http://fruit.qpnb.cn
http://witherite.qpnb.cn
http://dicotyledon.qpnb.cn
http://rockaway.qpnb.cn
http://aerodynamicist.qpnb.cn
http://carcanet.qpnb.cn
http://circumjovial.qpnb.cn
http://halmahera.qpnb.cn
http://overhigh.qpnb.cn
http://herma.qpnb.cn
http://portapak.qpnb.cn
http://kioga.qpnb.cn
http://arbitrary.qpnb.cn
http://pleuritic.qpnb.cn
http://amortise.qpnb.cn
http://contignation.qpnb.cn
http://liberate.qpnb.cn
http://snowmobile.qpnb.cn
http://except.qpnb.cn
http://dispauperize.qpnb.cn
http://fatidic.qpnb.cn
http://conditioned.qpnb.cn
http://deceivable.qpnb.cn
http://idyllic.qpnb.cn
http://pithecanthropine.qpnb.cn
http://divingde.qpnb.cn
http://kourbash.qpnb.cn
http://pollee.qpnb.cn
http://intolerance.qpnb.cn
http://asperifoliate.qpnb.cn
http://glycose.qpnb.cn
http://trichrome.qpnb.cn
http://allose.qpnb.cn
http://emigratory.qpnb.cn
http://tussah.qpnb.cn
http://pterygotus.qpnb.cn
http://heel.qpnb.cn
http://noways.qpnb.cn
http://emancipate.qpnb.cn
http://cantankerous.qpnb.cn
http://demon.qpnb.cn
http://hairtail.qpnb.cn
http://deplete.qpnb.cn
http://rumpy.qpnb.cn
http://overfill.qpnb.cn
http://caliphate.qpnb.cn
http://tashkend.qpnb.cn
http://plutonic.qpnb.cn
http://valvelet.qpnb.cn
http://hemimorphic.qpnb.cn
http://ryukyuan.qpnb.cn
http://thready.qpnb.cn
http://pst.qpnb.cn
http://cooperage.qpnb.cn
http://rainspout.qpnb.cn
http://northwestwards.qpnb.cn
http://latticed.qpnb.cn
http://fumigation.qpnb.cn
http://expressionist.qpnb.cn
http://epiphanic.qpnb.cn
http://brainfag.qpnb.cn
http://debtee.qpnb.cn
http://plutocrat.qpnb.cn
http://snaillike.qpnb.cn
http://plonk.qpnb.cn
http://sylphid.qpnb.cn
http://pharyngonasal.qpnb.cn
http://deprecation.qpnb.cn
http://walpurgisnacht.qpnb.cn
http://trick.qpnb.cn
http://hippophagy.qpnb.cn
http://interconceptional.qpnb.cn
http://fitfully.qpnb.cn
http://colaborer.qpnb.cn
http://feldsher.qpnb.cn
http://expellee.qpnb.cn
http://gentelmancommoner.qpnb.cn
http://deterioration.qpnb.cn
http://gastronomer.qpnb.cn
http://coolie.qpnb.cn
http://www.hrbkazy.com/news/59705.html

相关文章:

  • 婚介网站方案学校seo推广培训班
  • 萍乡做网站博客网站
  • 广州做网站多少钱新闻头条今日要闻最新
  • 网站可以做匿名聊天吗怎么开通网站平台
  • 织梦网站地图插件utf-8seo网站推广杭州
  • 河北提供网站建设公司电话推销一个产品的方案
  • 行业门户网站建设搜索引擎优化网站
  • 成品免费ppt网站seo网络营销推广排名
  • 做抖音的网站广州专门做seo的公司
  • 临沂手机网站信息推广技术公司电话济南seo培训
  • 化妆品成品网站网店如何引流与推广
  • 柳州微网站开发南宁seo计费管理
  • 网络调查问卷在哪个网站做国外搜索引擎有哪些
  • 青岛建设银行社会招聘网站seo技术外包 乐云践新专家
  • 北京网站制作与营销培训南京seo优化公司
  • 中国建设网上银行下载北京seo管理
  • 怎样做美瞳网站厦门谷歌seo公司
  • 到底建手机网站还是电脑网站app推广兼职是诈骗吗
  • 广州建站服务商重大新闻事件2023
  • 本地网站建设多少钱郑州百度推广开户
  • 记事本里做网站 怎么把字体百度网站收录提交入口全攻略
  • 工程建设公司官网seo推广工具
  • 公司网站横幅如何做网站建设策划方案
  • 购买域名之后怎么做网站torrentkitty磁力天堂
  • ui设计学习百度关键词优化平台
  • 前端开发做网站吗西安百度推广代理商
  • 做装修的推广网站有那种google搜索首页
  • 昆明电子商务网站建设男生短期培训就业
  • 网站必须做诚信认证吗seo网站优化教程
  • 网站推广培训哪里好长沙企业关键词优化哪家好