📜  用子树表示 tikz 中的二叉搜索树 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:21.751000             🧑  作者: Mango

代码示例1
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning}
\tikzset
{
    treenode/.style = {circle, draw=black, align=center, 
                          minimum size=1cm, anchor=center},
    subtree/.style  = {regular polygon, regular polygon sides=3, 
                          draw=black, align=center, 
                          minimum size=1cm, anchor=center}
}
\begin{document}

    \begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 5cm/#1,
    level distance = 1.5cm},scale=0.6, transform shape]
    \node [treenode] {$X$ \\ 100}
    child
    {
        node [treenode] {$Y$ \\ 50} 
        child
        {
            node [treenode] {$Z$ \\ 40} 
            child
            {
                node [treenode] {$S1$ \\ 30} 
            }
            child
            {
                node [treenode] {$S2$ \\ 60} 
            }
        }
        child [child anchor=north]
        {
            node [subtree] {$Z$ \\ 200} 
        }
    }
    child [child anchor=north]
    {
        node [subtree] {$Z$ \\ 200} 
    }
;
    \end{tikzpicture}
\end{document}