#include <bits/stdc++.h>
using
namespace
std;
struct
node {
int
data;
struct
node *left, *right;
};
struct
node* newnode(
int
data)
{
struct
node* temp =
new
node();
temp->data = data;
temp->left = temp->right = NULL;
return
temp;
}
void
cal(
struct
node* root)
{
if
(root == NULL) {
return
;
}
if
(root->left == NULL
&& root->right == NULL) {
return
;
}
else
{
if
(root->left != NULL
&& root->right != NULL) {
if
((root->left->left == NULL
&& root->left->right == NULL)
|| (root->right->left == NULL
&& root->right->right == NULL)) {
cout << root->data <<
" "
;
}
}
if
(root->left != NULL
&& root->right == NULL) {
if
(root->left->left == NULL
&& root->left->right == NULL) {
cout << root->data <<
" "
;
}
}
if
(root->right != NULL
&& root->left == NULL) {
if
(root->right->left == NULL
&& root->right->right == NULL) {
cout << root->data <<
" "
;
}
}
}
cal(root->left);
cal(root->right);
}
int
main()
{
node* root = newnode(20);
root->left = newnode(8);
root->right = newnode(22);
root->left->left = newnode(4);
root->left->right = newnode(12);
root->left->right->left = newnode(10);
root->left->right->right = newnode(14);
cal(root);
return
0;
}