Exemplo n.º 1
0
        public static void DoTree(Node tree, Action<Node> action)
        {
            if (tree == null) return;
            var left = Task.Factory.StartNew(() => DoTree(tree.Left, action));
            var right = Task.Factory.StartNew(() => DoTree(tree.Right, action));
            action(tree);

            try
            {
                Task.WaitAll(left, right);
            }
            catch (AggregateException)
            {
                //handle exceptions here
            }
        }
Exemplo n.º 2
0
        public void BuildTree()
        {
            _templates = new String[] { "aabc", "bba", "caac" };
            _templatesCount = _templates.Length;

            _root = new Node();
            var seed = (Int32)DateTime.Now.Ticks;
            BuildTreeStep(_root, DEPTH, seed);
            _treeCount = (Int32)Math.Pow(2, DEPTH + 1) - 1;
        }
Exemplo n.º 3
0
 private void SomeAction(Node node)
 {
     node.Data = node.Data.Replace("a", "12");
 }
Exemplo n.º 4
0
        private void BuildTreeStep(Node current, Int32 level, Int32 seed)
        {
            var rnd = new Random(seed);
            var index = rnd.Next(_templatesCount);
            current.Data = _templates[index];

            if (level == 0)
            {
                return;
            }

            current.Left = new Node();
            current.Right = new Node();
            BuildTreeStep(current.Left, level - 1, index - 5);
            BuildTreeStep(current.Right, level - 1, index + 5);
        }