#include <iostream>

  

using namespace std;

  

struct Node {

    int ;

    struct Node *left, *right;

};

  

struct Node* newNode(int val)

{

    struct Node* temp = new Node;

    temp->left = ;

    temp->right = NULL;

    temp->data = val;

    return temp;

}

  

int maxAtLevel(struct Node* root, int )

{

    

    if (root == NULL)

        return 0;

  

    

    

    if (level == 0)

        return root->data;

  

    int x = maxAtLevel(root->left, level - 1);

    int y = maxAtLevel(root->right, level - 1);

  

    

    return max(x, y);

}

  

int main()

{

    

    struct Node* root = NULL;

    root = newNode(45);

    root->left = newNode(46);

    root->left->left = newNode(18);

    root->left->left->left = newNode(16);

    root->left->left->right = newNode(2);

    root->left->right = newNode(17);

    root->left->right->left = newNode(24);

    root->left->right->right = newNode(21);

    root->right = newNode(15);

    root->right->left = newNode(22);

    root->right->left->left = newNode(37);

    root->right->left->right = newNode(41);

    root->right->right = newNode(19);

    root->right->right->left = newNode();

    root->right->right->right = newNode(29);

  

    int level = 3;

  

    cout << maxAtLevel(root, level);

  

    return 0;

}



Source link
thanks you RSS link
( https://www.geeksforgeeks.org/-the--node-at-a-given-level-in-a--/)

LEAVE A REPLY

Please enter your comment!
Please enter your name here