Created
August 16, 2017 19:06
-
-
Save AdhirRamjiawan/63c60008dbe7432518a2804348a28ccc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace LearnTreeDS | |
{ | |
public class Node | |
{ | |
public string Name { get; set; } | |
public bool Visited { get; set; } | |
public List<Node> Children { get; set; } = new List<Node>(); | |
} | |
class Program | |
{ | |
/* | |
_ R_ | |
/ | \ | |
1 2 3 | |
/ | \ | |
4 5 6 | |
*/ | |
public static void TraverseFn(Node currentNode) | |
{ | |
currentNode.Visited = true; | |
Console.WriteLine("Visited: " + currentNode.Name); | |
foreach (var child in currentNode.Children) | |
TraverseFn(child); | |
} | |
static void Main(string[] args) | |
{ | |
var Root = new Node() { Name = "Root" }; | |
var child1 = new Node() { Name = "1" }; | |
child1.Children.Add(new Node() { Name = "4" }); | |
child1.Children.Add(new Node() { Name = "5" }); | |
child1.Children.Add(new Node() { Name = "6" }); | |
Root.Children.Add(child1); | |
Root.Children.Add(new Node() { Name = "2" }); | |
Root.Children.Add(new Node() { Name = "3" }); | |
TraverseFn(Root); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment