外行人请教问题

rose200896 2008-07-12 07:17:48
编写算法实现以二叉链表为存储结构的二叉树的以下运算

(1) parent(root,x);

(2) delleft(root,x)

请教这题算法答案
...全文
85 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
rose200896 2008-07-25
  • 打赏
  • 举报
回复
redraiment 谢谢!

oo 没看明白题目,说明你的能力有限,多学着点!

redraiment 2008-07-23
  • 打赏
  • 举报
回复
typedef struct node
{
int x;
struct node * left;
struct node * right;
}tree;

tree * parent(tree * root, int x)
{
if (!root || root->x == x)
return NULL;
if (root->left && root->left->x == x)
return root;
if (root->right && root->right->x == x)
return root;
return parent(root->left, x) + parent(root->right, x);
}

void del_tree(tree * root)
{
if (!root) return;
if (root->left) del_tree(root->left);
if (root->right) del_tree(root->right);
free(root);
}

void delleft(tree * root, int x)
{
if (root->x == x)
{
del_tree(root->left);
root->left = NULL;
}
if (root->left) delleft(root->left, x);
if (root->right) delleft(root->right, x);
}
oo 2008-07-13
  • 打赏
  • 举报
回复
没看明白题目

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧