Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions Anurupa_hactober
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

#include <iostream>
using namespace std;

struct Node {
int key;
struct Node *left, *right;
};

// New node creation
struct Node *newNode(char k) {
struct Node *node = (struct Node *)malloc(sizeof(struct Node));
node->key = k;
node->right = node->left = NULL;
return node;
}

bool isFullBinaryTree(struct Node *root) {

// Checking for emptiness
if (root == NULL)
return true;

// Checking for the presence of children
if (root->left == NULL && root->right == NULL)
return true;

if ((root->left) && (root->right))
return (isFullBinaryTree(root->left) && isFullBinaryTree(root->right));

return false;
}

int main() {
struct Node *root = NULL;
root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
root->left->right->left = newNode(6);
root->left->right->right = newNode(7);

if (isFullBinaryTree(root))
cout << "The tree is a full binary tree\n";
else
cout << "The tree is not a full binary tree\n";
}

#include <iostream>
using namespace std;

struct Node {
int key;
struct Node *left, *right;
};

// New node creation
struct Node *newNode(char k) {
struct Node *node = (struct Node *)malloc(sizeof(struct Node));
node->key = k;
node->right = node->left = NULL;
return node;
}

bool isFullBinaryTree(struct Node *root) {

// Checking for emptiness
if (root == NULL)
return true;

// Checking for the presence of children
if (root->left == NULL && root->right == NULL)
return true;

if ((root->left) && (root->right))
return (isFullBinaryTree(root->left) && isFullBinaryTree(root->right));

return false;
}

int main() {
struct Node *root = NULL;
root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
root->left->right->left = newNode(6);
root->left->right->right = newNode(7);

if (isFullBinaryTree(root))
cout << "The tree is a full binary tree\n";
else
cout << "The tree is not a full binary tree\n";
}