把一个有序整数数组放到二叉树中
来源:互联网 发布:zepto.js h5滑动事件 编辑:程序博客网 时间:2024/05/13 08:52
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct student {
int value;
struct student *lchild;
struct student *rchild;
};
void arraytotree(int *a, int len, struct student **p) {
if(len) {
*p = (struct student*)malloc(sizeof(struct student));
(*p)->value = a[len/2];
arraytotree(a, len/2, &((*p)->lchild));
arraytotree(a+len/2+1, len-len/2-1, &((*p)->rchild));
} else {
*p = NULL;
}
}
void display_tree(struct student *head) {
if(head->lchild)display_tree(head->lchild);
printf("%d/t", head->value);
if(head->rchild)display_tree(head->rchild);
}
int main() {
int a[] = {1,2,3,4,9,10,33,56,78,90};
struct student *tree;
arraytotree(a, sizeof(a)/sizeof(a[0]), &tree);
printf("After convert:/n");
display_tree(tree);
printf("/n");
return 0;
}
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 把一个有序整数数组放到二叉树中
- 题目:把一个有序整数数组放到二叉树。
- 把一个有序整数数组放到二叉树
- 把一个有序整数数组放到二叉树。
- 把一个有序整数数组放到二叉树
- 把一个有序整数数组放到二叉树
- 怎样编写一个程序,把一个有序整数数组放到二叉树中
- 怎样编写一个程序,把一个有序整数数组放到二叉树中?
- 怎样编写一个程序,把一个有序整数数组放到二叉树中(按行输出)
- 编写一个程序,把一个有序整数数组放到二叉树中。
- 怎样编写一个程序,把一个有序整数数组放到二叉树中
- 5、怎样编写一个程序,把一个有序整数数组放到二叉树中
- 编写一个程序,把一个有序整数数组放到二叉树中
- 怎样编写一个程序,把一个有序整数数组放到二叉树中
- java图片缩放不失真(收集)
- 算法不会,尚能饭否之排序——折半插入排序(Binary Insert Sort)
- 设为首页JS,加入收藏夹js,加入收藏夹代码,设为首页代码,火狐和ie兼容
- 用GDB调试程序
- zoj_1654_最大匹配
- 把一个有序整数数组放到二叉树中
- ajax页面无法弹出对话框??
- mysql编码设置
- 我最喜欢的书(2-3岁)
- 2011-03-14~2011-03-16 竞彩足球
- [Mozilla] CVS下载源代码
- 面试—每日一题(4)
- GooleAppEngine(Python)中文页面
- linux时间同步命令