#include <bits/stdc++.h>
using
namespace
std;
struct
node {
struct
node *left, *right;
int
key;
};
node* newNode(
int
key)
{
node* temp =
new
node;
temp->key = key;
temp->left = temp->right = NULL;
return
temp;
}
void
cal(
struct
node* root)
{
if
(root == 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->key <<
" "
;
}
}
else
if
(root->left != NULL) {
if
(root->left->left != NULL
|| root->left->right != NULL) {
cout << root->key <<
" "
;
}
}
else
if
(root->right != NULL) {
if
(root->right->left != NULL
|| root->right->right != NULL) {
cout << root->key <<
" "
;
}
}
cal(root->left);
cal(root->right);
}
}
int
main()
{
struct
node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
cal(root);
return
0;
}