latex - 如何在 LaTex 中正确显示我的 AVL 树?独生左子直垂

标签 latex avl-tree xypic

下面的代码几乎可以完美运行,但是 9, 7 的 child 直接垂下而不是作为左 child 。我该如何纠正?

\usepackage{tikz}
\usepackage{xytree}
\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
    \node [circle,draw] {4}
      child {
        node [circle,draw] {2}
            child {node [circle,draw] {1}
       }
        child {
            node [circle,draw]{3}
        }
      }
      child {node [circle,draw] {6}
        child {node [circle,draw]  {5}
        }
      child {node [circle,draw]  {9}
        child {node [circle, draw]  {7}}
      }
    };

\end{tikzpicture}}

谢谢,CB

最佳答案

下面的代码对我有用。它基于您的代码,并进行了更改

1) 使用 tikz 库树和
2)单个节点(节点7)的格式改变

有关更多信息,请参阅 tikz 手册

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
    \node [circle,draw] {4}
      child {
        node [circle,draw] {2}
            child {node [circle,draw] {1}
       }
        child {
            node [circle,draw]{3}
        }
      }
      child {node [circle,draw] {6}
        child {node [circle,draw]  {5}
        }
      child {node [circle,draw]  {9}
        child[grow via three points={one child at (-1,-1) and two children at (-.5,1) and (.5,1)}] {node [circle, draw]  {7}}
      }
    };

\end{tikzpicture}

\end{document}

关于latex - 如何在 LaTex 中正确显示我的 AVL 树?独生左子直垂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2454526/

相关文章:

latex - 各种 latex 问题

shell - 在 Tex 文件中包含日期和时间

latex - 如何在LaTeX中使用TrueType字体

python - 找不到有效的 Python 解释器。请在您的 LaTeXTools 设置中设置 python 设置

binary-search-tree - WAVL(弱AVL)和红黑树有什么区别?

avl-tree - AVL树非递归

data-structures - 如何重新平衡随机二叉搜索树

latex - LaTeX中两个单独的xy-pic图之间的相等性