using
System;
using
System.Collections.Generic;
public
class
Node {
public
int
data;
public
Node left, right;
public
Node(
int
item)
{
data = item;
left = right =
null
;
}
}
public
class
GFG {
public
Node root;
public
Node NewNode(
int
data)
{
Node newNode =
new
Node(data);
newNode.left =
null
;
newNode.right =
null
;
return
newNode;
}
public
void
PrintNodes(Node root,
int
start,
int
end,
List<List<
int
> > ans,
int
level)
{
if
(root ==
null
) {
return
;
}
PrintNodes(root.left, start, end, ans, level + 1);
if
(level >= start && level <= end) {
ans[level - start].Add(root.data);
}
PrintNodes(root.right, start, end, ans, level + 1);
}
static
public
void
Main()
{
GFG tree =
new
GFG();
tree.root = tree.NewNode(1);
tree.root.left = tree.NewNode(2);
tree.root.right = tree.NewNode(3);
tree.root.left.left = tree.NewNode(4);
tree.root.left.right = tree.NewNode(5);
tree.root.right.left = tree.NewNode(6);
tree.root.right.right = tree.NewNode(7);
int
start = 2;
int
end = 3;
List<List<
int
> > ans
=
new
List<List<
int
> >(end - start + 1);
for
(
int
i = 0; i < end - start + 1; i++) {
ans.Add(
new
List<
int
>());
}
tree.PrintNodes(tree.root, start, end, ans, 1);
for
(
int
i = 0; i < ans.Count; i++) {
for
(
int
j = 0; j < ans[i].Count; j++) {
Console.Write(ans[i][j] +
" "
);
}
Console.WriteLine();
}
}
}