#include <iostream>
using namespace std;
struct Btree{
int num;
struct Btree *next;
struct Btree *prev;`enter code here`
};
struct Btree * head=NULL;
struct Btree* create(){
struct Btree* temp;
temp =(struct Btree*)malloc(sizeof(struct Btree));
return temp;
}
void insert(int x){
struct Btree* node,*t;
node=create();
node->num=x;
node->next=NULL;
node->prev=NULL;
if(head==NULL){
head=node;
}
else
{
t=head;
while(t!=NULL){
if(x>t->num){
if(t->next==NULL){
t->next=node;
}
t=t->next;
}
else if(x<t->num){
if(t->prev==NULL){
t->prev=node;
}
t=t->prev;
}
}
}
}
void printInorder(struct Btree* node)
{
if (node == NULL) {
return;
}
else
{
printInorder(node->prev);
cout << node->num << " ";
printInorder(node->next);
}
}
void display(){
struct Btree *t;
t=head;
printInorder(t);
}
int main() {
insert(10);
insert(20);
insert(4);
insert(140);
insert(5);
insert(6);
insert(70);
display();
return 0;
}
// Мне нужно вставить узлы в бинарное дерево, поэтому я создал две функции. Мне нужно рекурсивно обходить узлы, используя метод preOrder Traversal, но он проходит по нему и не выдает никаких выходных данных.Пожалуйста, помогите мне с этим кодом. Я думаю, что значение не вставляется. Но я не знаю, что с этим не так. Может кто-нибудь решить мне эту проблему. Это будет большая помощь для меня. Я не могу определитьошибка.