Ich war ein binären Suchbaum für meine Hausaufgaben zu machen, aber es wird keine Ausgabe für Inorder zeigt, Preorder und Postorder. Obwohl ich cout
in den inorder
preorder
und postorder
Funktionen verwende, gibt es mir keine Ausgabe. Der Fehler, den ich fühle, ist in createBst
Funktion noch ich es nicht sicher bin ... mir freundlicherweise helfen Sie :-)binärer Suchbaum: keine Ausgabe
#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;
}
_Keine Ausgabe ausgeben_. Dies ist eine ziemlich vage Aussage. Erhalten Sie Fehler beim Kompilieren? Was ist IDE, verwenden Sie, um dies zu kompilieren? –