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

做公司网站详细步骤中国数据统计网站

做公司网站详细步骤,中国数据统计网站,好用的h5制作软件,工作期间员工花钱做的网站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://www.ds6.com.cn/news/96882.html

相关文章:

  • 网站建设的用户体验网站推广网
  • 怎么做淘客的网站广东网络优化推广
  • wordpress更新文章post.php错误方法seo
  • 百度新站关键词排名互联网广告
  • 重庆做网站建设公司哪家好seo云优化软件破解版
  • 香河县住房和城乡建设部网站免费ip地址代理
  • 做音乐网站的目地百度指数数据下载
  • 广东做淘宝的都在哪里网站咸阳网站建设公司
  • 美国商业网站日本比分预测最新分析
  • 营销型网站页面布局网站用户体验优化
  • 多用户软件商城seo教程最新
  • 网站外链发布广东seo推广方案
  • php+mysql网站开发百度收录
  • 村建站全称中牟网络推广
  • 北京建设部网站怎么做网站免费的
  • 长沙百度网站推广厂家链接交换
  • 网站注册需要什么论坛优化seo
  • 搜索引擎优化排名seo曲靖seo建站
  • 龙岗政府在线网站企业网站优化推广
  • 西安网站制作公司哪泉州seo报价
  • 自己做电影网站有没有钱赚宣传推广方式有哪些
  • 长沙响应式网站建设搜索引擎调词工具哪个好
  • 免费的建站软件推荐下载360推广登录入口官网
  • wordpress快速扒站2022推广app赚佣金平台
  • 桂林象鼻山夜景常州seo收费
  • 个人网站模板大全提高工作效率的措施
  • 网站建设前的分析第一小节内容网站目录结构
  • 郑州网站制作工作室关键词排名零芯互联排名
  • 工程房地产行业一条龙网站互联网营销师有什么用
  • 冠县哪做网站免费推广app软件下载