Ejemplo n.º 1
0
 public static int TreeMaxHeight( BinaryNode node )
 {
     if( node == null ) return 0;
     int left_height = TreeMaxHeight( node.LeftNode );
     int right_height = TreeMaxHeight( node.RightNode );
     return ( left_height > right_height ) ? left_height + 1 : right_height + 1;
 }
Ejemplo n.º 2
0
        public void DrawTree( Canvas canvas, BinaryNode tree )
        {
            DrawingArea = canvas;

            var annotatedTree = Helpers.ToAnnotatedBinaryTree( tree );

            PrepareNode( annotatedTree );
            PerformLayout( annotatedTree );

            DrawNode( annotatedTree );
            DrawLines( annotatedTree );

            int treeHeight = Helpers.TreeMaxHeight( annotatedTree );
            int treeWidth = Helpers.TreeMaxWidth( annotatedTree );
            DrawingArea.Width = treeWidth * 50;
            DrawingArea.Height = treeHeight * 80;
        }
Ejemplo n.º 3
0
        public static AnnotatedTreeNode ToAnnotatedBinaryTree( BinaryNode node )
        {
            var annotatedNode = new AnnotatedTreeNode()
            {
                Payload = node.Payload,
                IsCompareSource = node.IsCompareSource,
                IsCompareTarget = node.IsCompareTarget
            };

            if( node.LeftNode != null || node.RightNode != null )
            {
                annotatedNode.Children = new List<AnnotatedTreeNode>();

                if( node.LeftNode != null )
                {
                    var leftNode = ToAnnotatedBinaryTree( node.LeftNode );

                    annotatedNode.Children.Add( leftNode );
                }

                if( node.RightNode != null )
                {
                    var rightNode = ToAnnotatedBinaryTree( node.RightNode );

                    annotatedNode.Children.Add( rightNode );
                }

                // Push an invisible node
                if( node.LeftNode != null && node.RightNode == null )
                {
                    annotatedNode.Children.Add( new AnnotatedTreeNode(){ IsInvisibleNode = true } );
                }
                else if( node.LeftNode == null && node.RightNode != null )
                {
                    annotatedNode.Children.Insert( 0, new AnnotatedTreeNode() { IsInvisibleNode = true } );
                }
            }

            return annotatedNode;
        }