首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

怎么用C语言实现这样一颗树呢,麻烦大家看看

2012-03-02 
如何用C语言实现这样一颗树呢,麻烦大家看看。typedefstructNodeT{structNodeT**childrenintdata}node对

如何用C语言实现这样一颗树呢,麻烦大家看看。
typedef   struct   NodeT{

          struct   NodeT   **children;
          int   data;
}node;

对应的创建,添加,删除,遍历等操作。。。。。

一设计到**我就有些晕,

希望大家多多指教,先谢谢拉!


[解决办法]
node* root = (node*)malloc(sizeof(node));
int num = 0;

printf( "请输入节点 %d - %d 的孩子数 : ", level, sub);
scanf( "%d ", &num);

if (num == 0)
{
root-> children = 0;
return root;
}

root-> children = (node**)malloc(sizeof(node*) * num);

while (num--)
{
root-> children[num] = (node*)malloc(sizeof(node));
}
[解决办法]
node* root = (node*)malloc(sizeof(node));
int num = 0;


scanf( "%d ", &num);


root-> children = (node**)malloc(sizeof(node*) * num);

while (num--)
{
root-> children[num] = (node*)malloc(sizeof(node));
}

热点排行