C语言实现的二叉树并显示,出不来结果啊,求解

shenleiwhu 2014-08-30 01:56:10
#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
/**
* 树节点定义
*/
typedef struct BinaryTreeNode {
char data;
struct BinaryTreeNode *leftNode, *rightNode;
} BinaryTreeNode, *BinaryTree;

/**
* 先序创建二叉树
*/
int createBitaryTree(BinaryTree *binaryTree) {

char ch;
scanf("%c", &ch);
if (ch ==' '){
*binaryTree = NULL;
}

else {
*binaryTree = (BinaryTree) malloc(sizeof(BinaryTreeNode));
(*binaryTree)->data = ch;
createBitaryTree(&(*binaryTree)->leftNode);
createBitaryTree(&(*binaryTree)->rightNode);
}
return 1;
}
/**
* 二叉树的遍历
*/
int leftSearch(BinaryTree binaryTree) {
if (binaryTree != NULL) {
printf("%c ", binaryTree->data);
leftSearch(binaryTree->leftNode);
leftSearch(binaryTree->rightNode);
return 0;
}
else{
return 1;

}
}
int main() {
printf("please input:");
BinaryTree bt;
createBitaryTree(bt);
leftSearch(bt);
return 0;
}

...全文
280 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
707wk 2014-08-30
  • 打赏
  • 举报
回复
引用 9 楼 truelance 的回复:
这是你自己定义的
lz这代码是你自己写的吗
熊熊大叔 2014-08-30
  • 打赏
  • 举报
回复
引用 7 楼 shenlei190810 的回复:
[quote=引用 4 楼 truelance 的回复:] createBitaryTree(BinaryTree *binaryTree) 等价于 createBitaryTree(BinaryTreeNode **binaryTree) 要传入的是一个二重指针
这里为什么要用二重指针[/quote] 这是你自己定义的
shenleiwhu 2014-08-30
  • 打赏
  • 举报
回复
引用 4 楼 truelance 的回复:
createBitaryTree(BinaryTree *binaryTree) 等价于 createBitaryTree(BinaryTreeNode **binaryTree) 要传入的是一个二重指针
这里为什么要用二重指针
shenleiwhu 2014-08-30
  • 打赏
  • 举报
回复
引用 2 楼 truelance 的回复:
在main()里调用 createBitaryTree(&bt);
为什么要用指向指针的指针呢?
cdsnfresh 2014-08-30
  • 打赏
  • 举报
回复
引用 3 楼 shenlei190810 的回复:
[quote=引用 2 楼 truelance 的回复:] 在main()里调用 createBitaryTree(&bt);
为什么啊BinaryTree 不就是一个指针嘛[/quote]类型和你定义的不一样,你函数的形参是BinaryTree*,你传的实参是BinaryTree
熊熊大叔 2014-08-30
  • 打赏
  • 举报
回复
createBitaryTree(BinaryTree *binaryTree) 等价于 createBitaryTree(BinaryTreeNode **binaryTree) 要传入的是一个二重指针
shenleiwhu 2014-08-30
  • 打赏
  • 举报
回复
引用 2 楼 truelance 的回复:
在main()里调用 createBitaryTree(&bt);
为什么啊BinaryTree 不就是一个指针嘛
熊熊大叔 2014-08-30
  • 打赏
  • 举报
回复
在main()里调用 createBitaryTree(&bt);
shenleiwhu 2014-08-30
  • 打赏
  • 举报
回复
输入ABC##D##E##输入的是对的啊,就是不出结果啊

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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