# How to draw circular linked list?

Here is what I have....

It gives me weird 2 dots at the end, and I only want 1 dot at the end, also I only want the first compartment of the last rectangle cross out, not the entire rectangle get cross. How can I fix that??

Here's the code I have.......Thanks ahead!

\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}

• Please make your code snippet compilable ... – Mensch Oct 3 '17 at 20:34
• – Torbjørn T. Oct 3 '17 at 22:07

I'll be nice and post an answer, but please do make complete examples in the future, so that we, for example, don't have to reverse engineer which libraries you've used.

Anyways, the double dot is because you've used edge, use to instead, as in tikz-cd Extra arrow tip with start anchor on edge v0.9b

With regard to the cross out, use the one split south and one split north anchors, which are at either end of the line separating the node parts.

Other things:

• I replaced the arrows library with arrows.meta, and the corresponding arrow tips from that (arrows still work, but is considered deprecated, see the manual).

• You can use the coordinate specification (a |- b) to get the point at the x-coordinate of a and y-coordinate of b, which is somewhat less verbose than the calc syntax you used. (But which one you prefer is a matter of preference.)

• The to path at the end extends the bounding box quite a bit, so I added a manual fix for that. (Uncomment the \useasboundingbox line to see the difference.)

\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}

• I need the first compartment of last rectangle gets cross, not the 2nd compartment.......... – user3390471 Oct 4 '17 at 1:02
• Oh......Sorry.....I used separate preamble document, forgot to copy paste the code........>-< – user3390471 Oct 4 '17 at 1:06
• Never mind, I figured it out....Thank you^^ – user3390471 Oct 4 '17 at 1:24
• @user3390471 Oh right, first, not second. Sorry. As you apparently figured out, that's of course just a matter of using D.north west/D.south west, instead of D.north east/D.south east. – Torbjørn T. Oct 4 '17 at 7:13