e_shop

Linear Search using C++ Language

 Data Structures and Algorithms:

Source Code

#include <iostream> 

using namespace std;

class node  

{  

    public: 

    int data;  

    node* left;  

    node* right;  

};  

int height_of_tree(node* node)  

{  

    if (node == NULL)  

        return 0;  

    else

    { 

        int left_height= height_of_tree(node->left);  

        int right_height= height_of_tree(node->right);  

        if (left_height > right_height)  

            return(left_height + 1);  

        else return(right_height + 1);  

    }  

}

node* new_Node(int data)  

{  

    node *Node = new node(); 

    Node->data = data;  

    Node->left = NULL;  

    Node->right = NULL;     

    return(Node);  

}   

int main()  

    struct node *root = new_Node(5);  

    root->left = new_Node(6);  

        root->right = new_Node(8);     

        root->left->left = new_Node(5);  

              root->left->right = new_Node(4);   

                root->right->right = new_Node(9);

                  

                   

    cout << "\n\tHeight of this Binary tree is=\t\a " <<height_of_tree(root);  

    return 0;  





Post a Comment

0 Comments

a