#include <iostream>
#include <queue>
using namespace std;
struct Node{
int data;
struct Node* left, *right;
};
// Function to count the full Nodes in a binary tree
int fullcount(struct Node* node){
// Check if tree is empty
if (!node){
return 0;
}
queue<Node *> myqueue;
// traverse using level order traversing
int result = 0;
myqueue.push(node);
while (!myqueue.empty()){
struct Node *temp = myqueue.front();
myqueue.pop();
if (temp->left && temp->right){
result++;
}
if (temp->left != NULL){
myqueue.push(temp->left);
}
if (temp->right != NULL){
myqueue.push(temp->right);
}
}
return result;
}
struct Node* newNode(int data){
struct Node* node = new Node;
node->data = data;
node->left = node->right = NULL;
return (node);
}
int main(void){
struct Node *root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);
root->left->left = newNode(40);
root->left->right = newNode(50);
root->left->left->right = newNode(60);
root->left->right->right = newNode(70);
cout <<"count is: "<<fullcount(root);
return 0;
}
Code Example |
---|
C :: elastic search url date |
C :: how to initiate pointer array with null in c |
C :: Letters and Digits Total |
C :: counting 7s in an integer c |
C :: data breach |
C :: c joystick arduino |
C :: esp rainmaker led |
C :: write the data in perticulare memmory loaction in C |
C :: How to scale all columns in dataframe in R- Method 2? |
C :: nc,manc |
C :: os.listdir to array |
C :: largest value in u32 |
C :: resize vm boot disk with empty space |
C :: inline function in c example |
C :: dynamic stack in c |
C :: function pointer in c |
C :: sort linked list c |
C :: c code to algorithm converter online |
C :: arduino analogwrite |
Dart :: TextStyle underline flutter |
Dart :: materialstateproperty |
Dart :: listtile remove padding flutter |
Dart :: open link with button flutter |
Dart :: flutter get device width |
Dart :: dart parse boolean from string |
Dart :: flutter lock orientation for page |
Dart :: flutter rotatedbox |
Dart :: dart check if object has property |
Dart :: flutter listtile |
Dart :: extend class flutter |