1

I am trying to draw a circular linked list that looks similar to the one in this question How to draw a circular linked list.

The difference is that I want the nodes arranged around a circle, which I have successfully done with the code below:

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

What I've failed to do is connect the nodes from the bullets, that are in the middle of one of the split rectangles, to the center following node's value's center. See the image below: Circular linked list

2
  • There isn't an anchor point associated with the text, but using the calc tikzlibrary you could use ($(A.west)!0.25!(A.east)$) for example. (This must be some new definition of linked list I had not been previously aware of.) Commented Oct 10, 2020 at 22:19
  • Thanks for the lead, I'll answer the question if no one does, when I'm done with the modifications
    – Sam
    Commented Oct 10, 2020 at 22:34

1 Answer 1

1

Thanks to @JohnKormylo lead. Here is the latex code for doing what is outlined in the question.

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

Result: Correct linked list

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .