using
System;
public
class
GFG {
public
class
Node {
public
int
data;
public
Node[] children;
public
Node(
int
n,
int
data)
{
children =
new
Node[n];
this
.data = data;
}
}
static
Node largest;
static
Node secondLargest;
static
void
findSecondLargestHelper(Node root)
{
if
(root ==
null
) {
return
;
}
if
(root.data > largest.data) {
secondLargest = largest;
largest = root;
}
else
if
(root.data > secondLargest.data
&& root.data != largest.data)
secondLargest = root;
foreach
(Node child
in
root.children)
findSecondLargestHelper(child);
}
static
Node findSecondLargest(Node root)
{
largest =
new
Node(0, Int32.MinValue);
secondLargest = largest;
findSecondLargestHelper(root);
return
secondLargest;
}
public
static
void
Main(
string
[] args)
{
int
n = 3;
Node root =
new
Node(n, 1);
root.children[0] =
new
Node(n, 2);
root.children[1] =
new
Node(n, 3);
root.children[2] =
new
Node(n, 4);
root.children[0].children[0] =
new
Node(n, 5);
root.children[0].children[1] =
new
Node(n, 6);
root.children[0].children[2] =
new
Node(n, 7);
findSecondLargest(root);
Console.Write(
"Second Largest Node is: "
);
Console.WriteLine(secondLargest.data);
}
}