主题:求助:为什么我写的二叉树只有输入没有输出
#include <iostream>
using namespace std;
struct Node
{
char data;
Node* lchild;
Node* rchild;
};
void createTree(Node** T);
void preorder(Node* T);
int main()
{
Node *tree ;
cout <<"intput:" << endl;
createTree(&tree);
cout << endl;
cout << "print:" << endl;
preorder(tree);
cout << endl;
system("pause");
return 0;
}
void createTree(Node** T)
{
char ch;
if(ch=getchar() == ' ')
(*T) = 0;
else
{
*T = new Node;
(*T)->data = ch;
createTree(&(*T)->lchild);
createTree(&(*T)->rchild);
}
}
void preorder(Node* T)
{
if(T)
{
cout << T->data;
preorder(T->lchild);
preorder(T->rchild);
}
}
using namespace std;
struct Node
{
char data;
Node* lchild;
Node* rchild;
};
void createTree(Node** T);
void preorder(Node* T);
int main()
{
Node *tree ;
cout <<"intput:" << endl;
createTree(&tree);
cout << endl;
cout << "print:" << endl;
preorder(tree);
cout << endl;
system("pause");
return 0;
}
void createTree(Node** T)
{
char ch;
if(ch=getchar() == ' ')
(*T) = 0;
else
{
*T = new Node;
(*T)->data = ch;
createTree(&(*T)->lchild);
createTree(&(*T)->rchild);
}
}
void preorder(Node* T)
{
if(T)
{
cout << T->data;
preorder(T->lchild);
preorder(T->rchild);
}
}