循环链表如何绘制?

循环链表如何绘制?

这是我所拥有的......在此处输入图片描述

它最后给我带来了奇怪的 2 个点,而我只想要最后 1 个点,而且我只想要最后一个矩形的第一个部分被划掉,而不是整个矩形都被划掉。我该如何解决这个问题??

这是我的代码......提前谢谢!

\begin{tikzpicture}[list/.style={rectangle split, rectangle split parts=2,
  draw, rectangle split horizontal}, >=stealth, start chain]
   \node[list,on chain] (A) {12};
   \node[list,on chain] (B) {99};
   \node[list,on chain] (C) {37};
   \node[list,on chain] (D) {\phantom{xx}};
   \draw (D.north east) -- (D.south west);
   \draw (D.north west) -- (D.south east);
   \draw[*->] let \p1 = (A.two), \p2 = (A.center) in (\x1,\y2) -- (B);
   \draw[*->] let \p1 = (B.two), \p2 = (B.center) in (\x1,\y2) -- (C);
   \draw[*->] let \p1 = (C.two), \p2 = (C.center) in (\x1,\y2) -- (D);
   \draw[*->] let \p1 = (D.two), \p2 = (D.center) in (\x1,\y2) edge[out=-10,in=190,distance=6cm] (A);
\end{tikzpicture}

答案1

我会很友善地发布答案,但请在将来提供完整的示例,以便我们不必对您使用过的库进行逆向工程。

无论如何,双点是因为你使用了edge,而是使用to,如tikz-cd 边缘带有起始锚点的额外箭头 v0.9b

对于删除,使用one split southone split north锚点,它们位于节点部分分隔线的两端。

其他事情:

  • arrows用 替换了该库arrows.meta,并从中替换了相应的箭头提示(arrows仍然有效,但被视为已弃用,请参阅手册)。

  • 您可以使用坐标规范(a |- b)来获取 x 坐标a和 y 坐标处的点b,这比您使用的语法稍微简洁一些calc。(但您更喜欢哪一个则取决于个人喜好。)

  • 末端的路径to将边界框延伸了不少,因此我对此进行了手动修复。(取消注释该\useasboundingbox行以查看差异。)

代码输出

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
  chains,
  shapes.multipart,
  arrows.meta % supersedes the arrows library
}
\begin{document}
\begin{tikzpicture}[
  list/.style={
     rectangle split,
     rectangle split parts=2,
     draw,
     rectangle split horizontal
  },
  dotarrow/.style={Circle-Stealth},
  start chain
]
   \node[list,on chain] (A) {12};
   \node[list,on chain] (B) {99};
   \node[list,on chain] (C) {37};
   \node[list,on chain] (D) {\phantom{xx}};
   \draw (D.north east) -- (D.one split south);
   \draw (D.south east) -- (D.one split north);
   \draw[dotarrow] (A.two |- A.center) -- (B);
   \draw[dotarrow] (B.two |- B.center)  -- (C);
   \draw[dotarrow] (C.two |- C.center)  -- (D);

   % the to path below extends the bounding box a lot, this fixes that
   \useasboundingbox ([shift={(-1.3cm,0)}]A.north west) rectangle ([shift={(1cm,-7mm)}]D.south east);
   \draw[dotarrow] (D.two |- D.center) to[out=-10,in=190,distance=6cm] (A);
\end{tikzpicture}
\end{document} 

相关内容