# How to draw array and linked list with connections?

I want to draw the image given below. I am able to draw array with some arrows but not able to draw the exact image.

See my code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pdftexcmds}
\usepackage{tikz}
\usepackage{booktabs}

\usetikzlibrary{positioning,matrix, arrows.meta}
\usetikzlibrary{decorations.pathreplacing}

\date{February 2018}

\begin{document}

\begin{tikzpicture}
\matrix (A) [ampersand replacement=\&,matrix of nodes, nodes={draw, minimum size=8mm},
column sep=-\pgflinewidth]{
3 \& 4 \& 4 \& 1 \& 4 \& 1 \& 2 \& 3\\};
\foreach \i [evaluate=\i as \ni using {int(\i)},
evaluate=\i as \ntext using {int(\i-1)}] in {1,3,4,6}
\draw [{Stealth}-, red!70] (A-1-\ni.south west)--++(-90:5mm) node[below] {\ntext};
\end{tikzpicture}

\end{document}


complied output:

Question : How to draw the image with tikz?

• Please edit your question to indent the code portion. Or use the {} button Feb 1, 2018 at 14:07
• And what is that actual question? Which bit are you stuck on? Feb 1, 2018 at 14:08

i understood, that you like with your code obtain the showed image:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
matrix,
positioning,
}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}[
node distance = 21mm and 7mm,
box/.style = {draw, minimum size=6mm, inner sep=0pt, outer sep=0pt, anchor=center},
pin edge = {Straight Barb-, shorten <=1mm,semithick}
]
\matrix (m) [matrix of nodes,
nodes={box},
column sep=-\pgflinewidth,
inner sep=0pt,
pin=120:Array]
{
1 & 2 & 3 &  \quad$\dotsm$\quad\vphantom{4}  & k     \\
};
\node (h2) [box,below=of m-1-2] {2};
\node (h1) [box, left=of h2,
\node (h3) [box,right=of h2]    {3};
\node (hk) [box,below right=of m-1-5] {$k$};
%
\draw[dashed,-Straight Barb, shorten <=1mm, shorten >=1mm]
(m-1-1.south) edge [bend right]   (h1.north)
(h1.north)    edge [bend right]   (m-1-1.south)
(m-1-2.south) edge [bend right]   (h2.north)
(h2.north)    edge [bend right]   (m-1-2.south)
(m-1-3.south) edge [bend right]   (h3.north)
(h3.north)    edge [bend right]   (m-1-3.south)
(m-1-5.south) edge [bend right]   (hk.north)
(hk.north)     to  [bend right]   (m-1-5.south);
%
\draw[-Straight Barb, transform canvas={yshift= 1mm}]
(h1) edge   (h2)    (h2) edge   (h3);
\draw[Straight Barb-, transform canvas={yshift=-1mm}]
(h1) edge   (h2)    (h2) edge   (h3);
%
\draw[loosely dotted, ultra thick, shorten <=3mm, shorten >=3mm]
(h3) -- (hk);
\end{tikzpicture}
\end{document}