code:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
class tnode
{
public:
int nodevalue;
tnode *left, *right;
//Constructor
tnode (int item, tnode *lptr = NULL,tnode *rptr = NULL)
{
nodevalue=item;
left=lptr;
right=rptr;
}
};
tnode *maxnode=NULL;
void findmaxvalue(tnode* tempnode)
{
if (tempnode!=NULL)
{
if (tempnode->nodevalue > maxnode->nodevalue)
{
maxnode=tempnode;
}
findmaxvalue(tempnode->left);
findmaxvalue(tempnode->right);
}
}
int main()
{
system("CLS");
//Building the tree
tnode *b,*c,*d,*e,*f,*root;
d= new tnode(5);
e= new tnode(38);
f= new tnode(42);
b= new tnode(15, d);
c= new tnode(40,e,f);
root=new tnode(35,b,c);
findmaxvalue(root);
cout<<"\n The maximum value in the tree is :: "<< maxnode->nodevalue;
getch();
return 0;
}
/code