0

No output is displaying binary search tree

Please help me in this Code is below 👇

30th May 2020, 6:06 AM
Rohit Kadayan
Rohit Kadayan - avatar
3 Réponses
0
#include <iostream> using namespace std; struct node { int data; node* left; node* right; }; void insert(node* root,int value) { node* ptr; node* n; n=new node; n->data= value; n->left=0; n-> right=0; if(root==0) root=n; else ptr=root; while(ptr!=0) { if(ptr->data>value) { if(ptr->left==0) ptr->left=n; else ptr=ptr->left; } else if(ptr->data<value) { if(ptr->right==0) ptr->right=n; else ptr=ptr->right; } } } void preorder(node* root) { if(root!=0) { cout<<root->data; preorder (root->left); preorder(root->right); } } int main() { node* root=0; insert(root,4); insert (root,5); insert(root,8); insert(root,3); preorder (root); return 0; }
30th May 2020, 6:07 AM
Rohit Kadayan
Rohit Kadayan - avatar
0
Please debugg please
30th May 2020, 9:33 AM
Rohit Kadayan
Rohit Kadayan - avatar