C语言操作随机生成的树结构

C TEST

There is a tree of nodes,each node contains a random interger number and a block of memory of random size.

树的每个节点包含一个随机整形数和一块随机大小的内存;

The number of child nodes for any parent is random,and the depth of the tree is also a random number.

每个父节点的子节点个数都是随机的,树的深度也是随机数值;

All the random numbers should be generated by random( ).

所有的随机数值使用random函数生成;


TASKS:

1. Create a tree of this kind.

创建一个这种类型的树结构;

2. Exam the tree,if a parent node and his child node both contain odd numbers,then insert a node containing an even number

检测这个树,如果父节点和他的子节点中的整形数均是奇数,那么插入一个节点;

     between the parent node and the child node.The inserted node may have only 1 child node.

此节点中的整形数为偶数,插入位置在父节点与子节点中间,且包含一个子节点;

3.  Traverse the tree, and print the number of each node.

遍历这棵树的所有节点,打印出每个节点中的整形数;

4.  Delete the tree and free the memory.

删除这棵树并且释放存储空间,即内存;


-------------------------------------------------------------------------------------------------------------------------------

 节点结构:

#include<stdio.h>
#include<stdlib.h>
</pre><pre name="code" class="cpp">typedef struct PTree
{
    int test_number;
    char *test_pointer;    //此处的申请空间有无问题,有malloc就应该有free,但可以释放结构实例
}PTree_s;




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值