Advertisement
Guest User

Untitled

a guest
Dec 15th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CustomTree
  8. {
  9.     class CustomTree
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             TreeNode root = new TreeNode(1);
  14.             root.LeftChildren.Add(new TreeNode(2));
  15.             root.LeftChildren.Add(new TreeNode(3));
  16.  
  17.             root.RightChildren.Add(new TreeNode(4));
  18.             root.RightChildren.Add(new TreeNode(5));
  19.  
  20.             root.LeftChildren.Find(x => x.Value == 2).LeftChildren.Add(new TreeNode(6));
  21.             root.LeftChildren.Find(x => x.Value == 2).LeftChildren.Add(new TreeNode(7));
  22.  
  23.             BinarySearchTree customTree = new BinarySearchTree(root);
  24.             Console.WriteLine(customTree);
  25.  
  26.             BinarySearchTree clonedTree = customTree.Clone() as BinarySearchTree;
  27.             TreeNode temp = clonedTree.Search(5);
  28.             clonedTree.Search(5).LeftChildren.Add(new TreeNode(10));
  29.  
  30.             Console.WriteLine();
  31.             Console.WriteLine("Cloned tree after modification:");
  32.             Console.WriteLine(clonedTree);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement