using
System;
using
System.Collections.Generic;
class
GFG{
public
class
Node
{
public
int
key;
public
List<Node> child =
new
List<Node>();
};
static
Node newNode(
int
key)
{
Node temp =
new
Node();
temp.key = key;
return
temp;
}
/// value
static
void
Siblings(Node root,
int
value)
{
int
flag = 0;
if
(root ==
null
)
return
;
Queue<Node> q =
new
Queue<Node>();
q.Enqueue(root);
while
(q.Count != 0)
{
Node temp = q.Peek();
q.Dequeue();
for
(
int
i = 0;
i < temp.child.Count; i++)
{
if
(temp.child[i].key == value)
{
flag = 1;
for
(
int
j = 0;
j < temp.child.Count; j++)
{
if
(value != temp.child[j].key)
Console.Write(temp.child[j].key +
" "
);
}
break
;
}
q.Enqueue(temp.child[i]);
}
}
if
(flag == 0)
Console.Write(
"No siblings!!"
);
}
static
Node constructTree()
{
Node root = newNode(10);
(root.child).Add(newNode(20));
(root.child).Add(newNode(30));
(root.child).Add(newNode(40));
(root.child[0].child).Add(newNode(50));
(root.child[0].child).Add(newNode(60));
(root.child[1].child).Add(newNode(70));
(root.child[1].child).Add(newNode(80));
(root.child[2].child).Add(newNode(90));
(root.child[2].child).Add(newNode(100));
(root.child[2].child).Add(newNode(110));
return
root;
}
public
static
void
Main(String[] args)
{
Node root = constructTree();
int
X = 30;
Siblings(root, X);
}
}