这幅图该怎么画?

这幅图该怎么画?

在此处输入图片描述

你好。

我怎样才能得到这样的图片?这是冒泡排序算法的一部分。

提前致谢。

答案1

如果你尝试自己做这样的事情,你就会意识到和 Ti 一起工作是多么有趣Z(甚至土拨鼠都可以做到这一点!;-)并且不依赖他人。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.multipart,positioning}
\begin{document}
\begin{tikzpicture}[my shape/.style={inner sep=5pt,font=\large,
rectangle split, rectangle split parts=4, draw, anchor=center,
rectangle split horizontal,rectangle split part fill={gray!50,white}}] 
\node [my shape] (a) 
{2\nodepart{two}8\nodepart{three}6\nodepart{four}4}; 
\node [my shape,right=3cm of a] (b) 
{2\nodepart{two}6\nodepart{three}8\nodepart{four}4}; 
\node [my shape,below=2cm of a] (c) 
{2\nodepart{two}6\nodepart{three}8\nodepart{four}4}; 
\node [my shape,right=3cm of c] (d) 
{2\nodepart{two}4\nodepart{three}8\nodepart{four}6}; 
\draw[latex-latex] ([yshift=-2mm]a.two south) -- ++(0,-0.3) -| ([yshift=-2mm]a.three south);
\draw[latex-latex] ([yshift=-2mm]c.two south) -- ++(0,-0.3) -| ([yshift=-2mm]c.four south);
\draw[-latex] ([xshift=2mm]a.east) -- ([xshift=-2mm]b.west) node[midway,above,font=\itshape] {intercambio};
\draw[-latex] ([xshift=2mm]c.east) -- ([xshift=-2mm]d.west) node[midway,above,font=\itshape] {intercambio};
\node[below=1.2cm of c,font=\itshape] {Lista inicial};
\node[below=1.2cm of d,font=\itshape] {Lista resultante};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

tabular具有、alignateqparbox节点连接的解决方案来自pstricks

\documentclass{article}
\usepackage{amsmath}
\usepackage{old-arrows}
\usepackage[svgnames, table]{xcolor}
\usepackage{array, bigstrut, eqparbox}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\begin{postscript}
\begin{alignat*}{2}
 & \eqmakebox[L]{\begin{tabular}{|*{4}{c|}}
  \hline
\cellcolor{Gainsboro}\bigstrut 2 & \rnode{A}{8} & \rnode{B}{6} & 4 \\
\hline
  \end{tabular}}
 & {}\xrightarrow{\quad\textit{intercambio}\quad}{}
 & \eqmakebox[R]{\begin{tabular}{|*{4}{c|}}
  \hline
\cellcolor{Gainsboro}\bigstrut 2 & 6 & 8 & 4 \\
\hline
  \end{tabular}} \\[3ex]%
 & \eqmakebox[L]{\begin{tabular}{|*{4}{c|}}
 \hline
\cellcolor{Gainsboro}\bigstrut 2 & \Rnode{C}{6} & 8 & \Rnode{D}{4} \\
\hline
 \end{tabular}}
 &{} \xrightarrow{\quad\textit{intercambio}\quad}{}
 & \eqmakebox[R]{\begin{tabular}{|*{4}{c|}}
 \hline
\cellcolor{Gainsboro}\bigstrut 2 & 4 & 8 & 6 \\
\hline
 \end{tabular}} \\[3ex]%
 & \eqmakebox[L]{\textit{Lista inicial}} & & \eqmakebox[R]{\textit{Lista resultante}}
 \end{alignat*}
\psset{linewidth=0.5pt, arrows=<->, arrowinset=0.12, angle=-90, arm=2.5mm, nodesep=8pt}
\ncbar{A}{B}
\ncbar{C}{D}
\end{postscript}

\end{document} 

在此处输入图片描述

相关内容