使用 Tikz 绘制用箭头链接的数组数据结构

使用 Tikz 绘制用箭头链接的数组数据结构

我想使用 TikZ 实现以下带有箭头的两个数组的图像表示。

在此处输入图片描述

请提供一些提示以便朝着正确的方向前进。

答案1

欢迎!基于 Zarko 的最近的答案

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, fit, positioning,calc}

\begin{document}
% from https://tex.stackexchange.com/a/409901/121799
\begin{tikzpicture}[
    node distance = 0pt,
      start chain = A going right,
      start chain = B going right,
      base/.style = {draw,rectangle,minimum height=7mm, outer sep=0pt,fill=green},
      boxA/.style = {base,minimum width=15mm, on chain=A,fill=green},
      boxB/.style = {base,minimum width=15mm, on chain=B,fill=green}
                    ]    
\node[base, on chain=A] (nodeAa)       {$2/5/8$};
\node[boxA] (nodeAb)   {$1/7/9$};
\node[boxA] (nodeAc)   {$2/3/9$};
\node[boxA] (nodeAd)   {$2/7/12$};
\node[boxA] (nodeAe)   {$1/15/15$};
\node[boxA] (nodeAf)   {$2/9/15$};
\node[boxA] (nodeAg)   {$1/8/17$};
%
\node[thick,inner sep=0pt, fit=(A-1) (A-7)] {};
%
\node[base, on chain=B,below=1cm of nodeAa] (nodeBa)       {$2/5/8$};
\node[boxB] (nodeBb)   {$1/7/9$};
\node[boxB] (nodeBc)   {$2/3/9$};
\node[boxB] (nodeBd)   {$2/7/12$};
\node[boxB] (nodeBe)   {$1/15/15$};
\node[boxB] (nodeBf)   {$2/9/15$};
\node[boxB] (nodeBg)   {$1/8/17$};
%
\node[thick,inner sep=0pt, fit=(B-1) (B-7)] {};
%
\draw[-latex] ($(nodeAa.south)-(0,0.7cm)$) -- (nodeAa) node[midway,left]{First Element};
\draw[-latex] ($(nodeAd.south east)-(0.2cm,0.7cm)$) -- ($(nodeAd.south east)-(0.2cm,0)$)
node[midway,right]{Second Element};
\draw[latex-latex,out=30,in=150] (nodeAd.north) to (nodeAe.north east);
\draw[latex-latex,out=150,in=30] (nodeAd.north) to (nodeAc.north west);
\draw[-latex] ($(nodeBa.south)-(0,0.7cm)$) -- (nodeBa) node[midway,right]{OK Element};
\draw[-latex] (nodeAd.south) to (nodeBc.north);
\draw[-latex] (nodeAc.south) to (nodeBd.north);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容