- 论坛徽章:
- 3
|
本帖最后由 cjaizss 于 2011-11-24 15:03 编辑
既然是递归,代码量就少了.
cjaizss 发表于 2011-11-24 14:42 ![]()
哦,叶子.........
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct _tree_node_t {
- int data;
- struct _tree_node_t* son[10];
- }tree_node_t ;
- typedef struct _list_node_t {
- int date;
- struct _list_node_t *next;
- } list_node_t;
- list_node_t* create_list(tree_node_t *tree) {
- list_node_t *ret,*tmp;
- int i;
- if(tree == NULL)return NULL;
-
- for(i=0,ret=NULL;i<10;i++) {
- if(tree->son[i]!=NULL) {
- if(ret == NULL)
- tmp = ret = create_list(tree->son[i]);
- else
- tmp->next = create_list(tree->son[i]);
- }
- }
- if(ret == NULL) {
- ret = (list_node_t*)malloc(sizeof(list_node_t));
- if(ret!=NULL) {
- ret->next = NULL;
- ret->data = tree->data;
- }
- }
- return ret;
- }
-
-
复制代码 |
|