使用 Tikz 绘制一个循环链表,其中节点围绕一个圆圈

使用 Tikz 绘制一个循环链表,其中节点围绕一个圆圈

我正在尝试绘制一个类似于这个问题中的循环链表如何绘制循环链表

不同之处在于我希望节点排列在一个圆圈周围,我已经使用下面的代码成功完成了:

          \begin{center}
           \begin{tikzpicture}[scale=2.5,list/.style={
                rectangle split,
                rectangle split parts=2,
                rectangle split horizontal,
                rectangle split part fill={red!30,blue!20},
                rounded corners,
                draw=black, thick,
                minimum height=0.65cm,
                text width=1cm,
                text centered,
           }]
                \node [list] at (0 * 360/6: 1.5) (A) {$\bullet$ \nodepart{two} \texttt{Head}};
                \node [list] at (1 * 360/6: 1.5) (B) {$\bullet$ \nodepart{two} \texttt{B}};
                \node [list] at (2 * 360/6: 1.5) (C) {$\bullet$ \nodepart{two} \texttt{C}};
                \node [list] at (3 * 360/6: 1.5) (D) {\texttt{D} \nodepart{two} $\bullet$};
                \node [list] at (4 * 360/6: 1.5) (E) {\texttt{E} \nodepart{two} $\bullet$};
                \node [list] at (5 * 360/6: 1.5) (F) {\texttt{F} \nodepart{two} $\bullet$};

                \draw[->] let \p1 = (A.one), \p2 = (A.two) in [bend right] (\x1,\y2) [bend right] to (B.two);
                \draw[->] let \p1 = (B.one), \p2 = (B.center) in (\x1,\y2) [bend right] to (C);
                \draw[->] let \p1 = (C.one), \p2 = (C.center) in (\x1,\y2) [bend right] to (D.one);
                \draw[->] let \p1 = (D.two), \p2 = (D.center) in (\x1,\y2) [bend left] to (E.one);
                \draw[->] let \p1 = (E.two), \p2 = (E.center) in (\x1,\y2) [bend left] to (F.one);
                \draw[->] let \p1 = (F.two), \p2 = (F.center) in (\x1,\y2) [bend right] to (A.one);
           \end{tikzpicture}
      \end{center}

我没能做到的是将位于其中一个分割矩形中间的项目符号节点连接到节点值中心之后的中心。参见下图: 循环链表

答案1

感谢@JohnKormylo 的领导。以下是用于执行问题中概述的操作的乳胶代码。

          \begin{center}
           \begin{tikzpicture}[scale=2.5,list/.style={
                rectangle split,
                rectangle split parts=2,
                rectangle split horizontal,
                rectangle split part fill={red!30,blue!20},
                rounded corners,
                draw=black, thick,
                minimum height=0.65cm,
                text width=1cm,
                text centered,
           }]
                \node [list] at (0 * 360/6: 1.5) (A) {$\bullet$ \nodepart{two} \texttt{A}};
                \node at (0 *360/6: 2.3) {\texttt{Head}};
                \node [list] at (1 * 360/6: 1.5) (B) {$\bullet$ \nodepart{two} \texttt{B}};
                \node [list] at (2 * 360/6: 1.5) (C) {$\bullet$ \nodepart{two} \texttt{C}};
                \node [list] at (3 * 360/6: 1.5) (D) {\texttt{D} \nodepart{two} $\bullet$};
                \node [list] at (4 * 360/6: 1.5) (E) {\texttt{E} \nodepart{two} $\bullet$};
                \node [list] at (5 * 360/6: 1.5) (F) {\texttt{F} \nodepart{two} $\bullet$};

                \draw[->] ($(A.west)!0.25!(A.east)$) [bend right] to ($(B.east)!0.1!(B.west)$);
                \draw[->] ($(B.west)!0.25!(B.east)$) [bend right] to ($(C.east)!0.1!(C.west)$);
                \draw[->] ($(C.west)!0.25!(C.east)$) [bend right] to ($(D.west)!0.1!(D.east)$);
                \draw[->] ($(D.east)!0.25!(D.west)$) [bend left] to ($(E.west)!0.1!(E.east)$);
                \draw[->] ($(E.east)!0.25!(E.west)$) [bend left] to ($(F.west)!0.1!(F.east)$);
                \draw[->] ($(F.east)!0.25!(F.west)$) [bend right] to ($(A.east)!0.1!(A.west)$);
           \end{tikzpicture}
      \end{center}

结果: 正确的链表

相关内容