내 숙제에 대한 이진 검색 트리를 만들고 있었다지만 inorder를 에 대한 출력을 표시되지, 예약 주문 및 postorder. 비록 내가 cout
을 inorder
preorder
과 postorder
기능으로 사용하고 있지만 아직 출력이 나오지 않습니다. 내가 느끼는이 오류는 아직 내가 은을받지 못한이진 검색 트리 : 없음 출력
createBst(r, val);
OP에서
#include <iostream>
using namespace std;
struct node
{
int info;
struct node *left;
struct node *right;
}*r;
struct node * createBst(struct node *r, int val)
{
if (r == NULL)
{
r = new node;
r->info = val;
r->left = NULL;
r->right = NULL;
}
else if (val <= r->info)
{
// cout<<r->left<<" ";
r->left = createBst(r->left, val);
}
else
{
r->right = createBst(r->right, val);
cout << r->right << " ";
}
return r;
}
void inOrder(struct node *r)
{
if (r != NULL)
{
inOrder(r->left);
cout << r->info;
inOrder(r->right);
}
}
void preOrder(struct node *r)
{
if (r != NULL)
{
cout << r->info;
preOrder(r->left);
preOrder(r->right);
}
}
void postOrder(struct node *r)
{
if (r != NULL)
{
postOrder(r->left);
postOrder(r->right);
cout << r->info;
}
}
int main()
{
r = NULL;
int n, val;
cout << "Enter the number of element" << endl;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> val;
//cout<<"check";
createBst(r, val);
}
cout << "Inorder" << endl;
//cout<<r->info<<endl;
inOrder(r);
cout << endl;
cout << "PreOrder" << endl;
preOrder(r);
cout << endl;
cout << "PostOrder" << endl;
postOrder(r);
cout << endl;
}
_ 출력하지 않음 _. 이것은 꽤 모호한 진술이다. 컴파일 중 오류가 있습니까? 이 IDE를 컴파일하는 데 사용하고있는 IDE는 무엇입니까? –