将一个有序整数数组放在一个二叉树中
来源:互联网 发布:上瘾网络剧猛其其花絮 编辑:程序博客网 时间:2024/05/25 21:36
#include <stdio.h>#include <windows.h>#include <iostream>using namespace std;struct student{ int vaule; struct student *lchild; struct student *rchild;};void arraytotree(int *a,int len,struct student*&p){ if (len>0) { p = new student; int mid = len / 2; (p)->vaule = a[mid]; arraytotree(a, mid, p->lchild); arraytotree(a + mid + 1, len - mid - 1, p->rchild); } else { p = NULL; }}void display_tree(struct student *head){ if (NULL != head) { display_tree(head->lchild); cout << head->vaule << endl; display_tree(head->rchild); }}int main(){ int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; struct student *tree=NULL; arraytotree(a, sizeof(a) / sizeof(a[0]), tree); printf("After convert:"); display_tree(tree); system("pause"); return 0; }
阅读全文
0 0
- 将一个有序整数数组放在一个二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 怎样编写一个程序,把一个有序整数数组放到二叉树中
- 怎样编写一个程序,把一个有序整数数组放到二叉树中?
- 怎样编写一个程序,把一个有序整数数组放到二叉树中(按行输出)
- 编写一个程序,把一个有序整数数组放到二叉树中。
- 怎样编写一个程序,把一个有序整数数组放到二叉树中
- 5、怎样编写一个程序,把一个有序整数数组放到二叉树中
- 编写一个程序,把一个有序整数数组放到二叉树中
- 怎样编写一个程序,把一个有序整数数组放到二叉树中
- 怎样编写一个程序,把一个有序整数数组放到二叉树中?
- 86 怎样编写一个程序,把一个有序整数数组放到二叉树中
- 有n个有序的整数放在一维数组中,输入一个数,将该数放入数组合适的位置,使插入该数后,数组中的元素仍然有序;
- 题目:把一个有序整数数组放到二叉树。
- Hadoop浅见
- Java基础知识
- 基线问题
- AQS
- Hibernate中addEntity与Transformers.aliasToBean的区别
- 将一个有序整数数组放在一个二叉树中
- CodeForces
- 比onload更快的DOMContentLoaded,readystatechange,doscroll的DOM加载事件
- Linux ssh自动登录的4种实现方法
- JavaScript入门(四)
- python中sort和sorted总结
- C++7.18
- git出现 *** Please tell me who you are. Run...... 错误
- CRC校验算法