Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. public class Node<T>
  4. {
  5.     public Node(T value)
  6.     {
  7.         this.Value = value;
  8.         this.Children = new List<Node<T>>();
  9.     }
  10.  
  11.     public T Value { get; set; }
  12.     public IList<Node<T>> Children { get; private set; }
  13.  
  14.     public void PrintTree()
  15.     {
  16.         Console.WriteLine("Tree");
  17.         this.Print(string.Empty, true);
  18.     }
  19.  
  20.     private void Print(string prefix, bool isTail)
  21.     {
  22.         Console.WriteLine(prefix + (isTail ? "└── " : "├── ") + this.Value);
  23.         for (int i = 0; i < this.Children.Count - 1; i++)
  24.             this.Children[i].Print(prefix + (isTail ? "    " : "│   "), false);
  25.  
  26.         if (this.Children.Count >= 1)
  27.             this.Children[this.Children.Count - 1].Print(prefix + (isTail ? "    " : "│   "), true);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement