#include <bits/stdc++.h>
using
namespace
std;
struct
Node {
struct
Node* left;
struct
Node* right;
int
data;
Node(
int
data)
{
this
->data = data;
this
->left = NULL;
this
->right = NULL;
}
};
int
height(
struct
Node* root)
{
if
(root == NULL)
return
0;
int
lheight = height(root->left);
int
rheight = height(root->right);
return
max(1 + lheight, 1 + rheight);
}
void
leftToRight(
struct
Node* root,
int
level)
{
if
(root == NULL)
return
;
if
(level == 1)
cout << root->data <<
" "
;
else
if
(level > 1) {
leftToRight(root->left, level - 1);
leftToRight(root->right, level - 1);
}
}
void
rightToLeft(
struct
Node* root,
int
level)
{
if
(root == NULL)
return
;
if
(level == 1)
cout << root->data <<
" "
;
else
if
(level > 1) {
rightToLeft(root->right, level - 1);
rightToLeft(root->left, level - 1);
}
}
void
ReverseClockWiseSpiral(
struct
Node* root)
{
int
i = 1;
int
j = height(root);
int
flag = 0;
while
(i <= j) {
if
(flag == 0) {
rightToLeft(root, j);
flag = 1;
j--;
}
else
{
leftToRight(root, i);
flag = 0;
i++;
}
}
}
int
main()
{
struct
Node* root =
new
Node(1);
root->left =
new
Node(2);
root->right =
new
Node(3);
root->left->left =
new
Node(4);
root->right->left =
new
Node(6);
root->right->right =
new
Node(7);
root->left->right =
new
Node(5);
ReverseClockWiseSpiral(root);
return
0;
}