binary search tree operations give me modifications as segmentation fault or no output is coming

#include<iostream.h>
struct bstnode{int data;
bstnode *right;
bstnode *left;}*t=NULL;
void insert(bstnode *&b,int k)
{
if(b==NULL)
{b=new bstnode;
b->data=k;
b->right=NULL;
b->left=NULL;}
else
if(k>b->data)
{insert(b->right,k);
}
else
{insert(b->left,k);
}
}
int findmax(bstnode *&b)
{if(b->right==NULL)
return b->data;
else
findmax(b->right);
}
int findmin(bstnode *&b)
{if(b->left==NULL)
return b->data;
else
findmin(b->left);
}
int find(bstnode *&b,int u)
{if(u==b->data)
{return u;}
else
if(u>b->data)
{find(b->right,u);}
else
{find(b->left,u);}
}
void dlrprint(bstnode *&b)
{if(b!=NULL)
{cout<<b->data;
dlrprint(b->left);
dlrprint(b->right);
}//else
//{return;}}
}
void ldrprint(bstnode *&b)
{if(b!=NULL)
{ldrprint(b->left);
cout<<b->data;
ldrprint(b->right);}}
main()
{int h,g;
insert(t,25);
g=findmax(t);
cout<<g;
cin>>h;
getchar();
}
Last edited on
its easy man,use ampersand in functions
thank u so much.........excellent i got it.......
u are awesome
yeah,i know
Topic archived. No new replies allowed.