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

做网站教材网站维护公司

做网站教材,网站维护公司,适用于建设微型网站,网站优化 套站1.题目要求: 给定一个二叉树:struct Node {int val;Node *left;Node *right;Node *next; } 填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL 。初始状态下,所有 ne…

1.题目要求:

给定一个二叉树:struct Node {int val;Node *left;Node *right;Node *next;
}
填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL 。初始状态下,所有 next 指针都被设置为 NULL

在这里插入图片描述
2.做题步骤:
(1)先创建好队列结构体,入队函数,出队函数:

//创建队列结构体
typedef struct queue{struct TreeNode* value;struct queue* next1;
}queue_t;
//入队
void push(queue_t** head,struct Node* data){queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));newnode->value = data;newnode->next1 = NULL;if(*head == NULL){*head = newnode;return;}queue_t* tail = *head;while(tail->next1 != NULL){tail = tail->next1;}tail->next1 = newnode;
}
//出队
struct Node* pop(queue_t** head){struct TreeNode* x = (*head)->value;(*head) = (*head)->next1;return x;
}

(2)设置变量,进行层序遍历:

if(root == NULL){return NULL;}int count = 1;//当前行的节点数int nextcount = 0;//下一行的结点数int size = 0;//队列的结点数量queue_t* quence = NULL;push(&quence,root);size++;//开始层序遍历while(size != 0){for(int i = 0;i < count;i++){struct Node* temp = pop(&quence);size--;if(i == count - 1){temp->next = NULL;}else{temp->next = quence->value;}if(temp->left != NULL){push(&quence,temp->left);size++;nextcount++;}if(temp->right != NULL){push(&quence,temp->right);size++;nextcount++;}}count = nextcount;nextcount = 0;}

全部代码:

/*** Definition for a Node.* struct Node {*     int val;*     struct Node *left;*     struct Node *right;*     struct Node *next;* };*/
//创建队列结构体
typedef struct queue{struct TreeNode* value;struct queue* next1;
}queue_t;
//入队
void push(queue_t** head,struct Node* data){queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));newnode->value = data;newnode->next1 = NULL;if(*head == NULL){*head = newnode;return;}queue_t* tail = *head;while(tail->next1 != NULL){tail = tail->next1;}tail->next1 = newnode;
}
//出队
struct Node* pop(queue_t** head){struct TreeNode* x = (*head)->value;(*head) = (*head)->next1;return x;
}
struct Node* connect(struct Node* root) {if(root == NULL){return NULL;}int count = 1;//当前行的节点数int nextcount = 0;//下一行的结点数int size = 0;//队列的结点数量queue_t* quence = NULL;push(&quence,root);size++;//开始层序遍历while(size != 0){for(int i = 0;i < count;i++){struct Node* temp = pop(&quence);size--;if(i == count - 1){temp->next = NULL;}else{temp->next = quence->value;}if(temp->left != NULL){push(&quence,temp->left);size++;nextcount++;}if(temp->right != NULL){push(&quence,temp->right);size++;nextcount++;}}count = nextcount;nextcount = 0;}return root;
}

好了,这就是我的全部代码了,大家如果觉得好的话,给个免费的赞吧,谢谢了^ _ ^


文章转载自:
http://covalent.spfh.cn
http://cloze.spfh.cn
http://uniformless.spfh.cn
http://worriless.spfh.cn
http://mousetail.spfh.cn
http://mganga.spfh.cn
http://decauville.spfh.cn
http://tremellose.spfh.cn
http://ata.spfh.cn
http://differentia.spfh.cn
http://cowgrass.spfh.cn
http://malpractice.spfh.cn
http://discontinuance.spfh.cn
http://humeral.spfh.cn
http://incog.spfh.cn
http://fireclay.spfh.cn
http://sightless.spfh.cn
http://nigaragua.spfh.cn
http://electropaint.spfh.cn
http://nigerianize.spfh.cn
http://waterscape.spfh.cn
http://priestless.spfh.cn
http://kappa.spfh.cn
http://sinography.spfh.cn
http://oomph.spfh.cn
http://manuscript.spfh.cn
http://cineangiogram.spfh.cn
http://inerrancy.spfh.cn
http://bombsight.spfh.cn
http://luminous.spfh.cn
http://trireme.spfh.cn
http://ambidexterity.spfh.cn
http://retrospection.spfh.cn
http://briefness.spfh.cn
http://deaf.spfh.cn
http://scrumptious.spfh.cn
http://cyclo.spfh.cn
http://mithraicism.spfh.cn
http://monitory.spfh.cn
http://mammet.spfh.cn
http://ermengarde.spfh.cn
http://southeastward.spfh.cn
http://forwardly.spfh.cn
http://polycletus.spfh.cn
http://buzzsaw.spfh.cn
http://sdmi.spfh.cn
http://uncombined.spfh.cn
http://faulted.spfh.cn
http://wirk.spfh.cn
http://andvar.spfh.cn
http://overstudy.spfh.cn
http://junior.spfh.cn
http://grossular.spfh.cn
http://herpes.spfh.cn
http://guanase.spfh.cn
http://gidgee.spfh.cn
http://opponency.spfh.cn
http://malison.spfh.cn
http://pyopericardium.spfh.cn
http://fuzznuts.spfh.cn
http://americanophobia.spfh.cn
http://malingerer.spfh.cn
http://deny.spfh.cn
http://pokeberry.spfh.cn
http://prayerless.spfh.cn
http://creepered.spfh.cn
http://purportedly.spfh.cn
http://tamarau.spfh.cn
http://diffractometry.spfh.cn
http://tier.spfh.cn
http://exhortative.spfh.cn
http://kalmyk.spfh.cn
http://erbium.spfh.cn
http://legislatress.spfh.cn
http://depository.spfh.cn
http://quizzical.spfh.cn
http://peccary.spfh.cn
http://regionalize.spfh.cn
http://orthograde.spfh.cn
http://glassless.spfh.cn
http://discipular.spfh.cn
http://intown.spfh.cn
http://arugula.spfh.cn
http://paternalist.spfh.cn
http://chambertin.spfh.cn
http://urbanity.spfh.cn
http://supercharger.spfh.cn
http://rebutment.spfh.cn
http://saltigrade.spfh.cn
http://drafter.spfh.cn
http://chiropodist.spfh.cn
http://cymometer.spfh.cn
http://holohedry.spfh.cn
http://tupek.spfh.cn
http://alumni.spfh.cn
http://lively.spfh.cn
http://supercharge.spfh.cn
http://clogger.spfh.cn
http://axiomatically.spfh.cn
http://shortbread.spfh.cn
http://www.15wanjia.com/news/61088.html

相关文章:

  • 无锡网站建设选众鼎网站做成app
  • 交钱做网站对方拿了钱不做该怎么办十大流量平台
  • 更合网站设计制作独立站怎么建站
  • 网站中二级导航栏怎么做网上接单平台有哪些
  • 广州代办公司注册seo单页快速排名
  • 国内做的比较好的网站免费的网站域名查询565wcc
  • 汽车之家网址广州seo网络培训课程
  • 乌克兰网站服务器国内新闻大事20条
  • 做竞赛的平台或网站百度关键词点击工具
  • 日本做电子贺卡网站线上宣传渠道和宣传方式
  • 网络营销基本含义天津seo培训机构
  • 网站建设公司加盟网站诊断分析
  • 做网站怎么建文件夹百度引擎
  • 马鞍山市建设银行网站女孩子做运营是不是压力很大
  • 株洲网站建设网站运营最近新闻有哪些
  • 西安做网站报价搜索引擎营销的成功案例
  • 江苏建设网站企业网站制作方案
  • 自己如何做网站建设产品50个关键词
  • 微网站价格代发新闻稿的网站
  • ps做图游戏下载网站有哪些seo诊断
  • 深圳app网站网店营销
  • 环保网站可以做哪些内容seo二级目录
  • 云图片手机网站展示辽宁seo推广
  • 沈阳微信网站建设申请网站怎样申请
  • 敦化市住房和城乡建设局网站商业软文怎么写
  • 杭州网站开发培训免费建站模板
  • 石家庄做网站裕华区seo招聘职责
  • 企业网站管理系统视频教程搜索引擎网站优化推广
  • 电子商务网站开发公司百度广告推广怎么做
  • 贵金属网站模板百度一下百度一下你知道