答案1
你可以从以下代码开始:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{tikzpicture}[
mymatrix/.style={
matrix of nodes,
column sep=-\pgflinewidth,
nodes={minimum width=8mm, draw},
row 2/.style={%
nodes={draw=none}},
},
]
\matrix[mymatrix] (A1) {|[fill=violet!30, label=left:$A$]|5&2&4&6&|[fill=green]|1&3\\1&2&3&4&5&6\\};
\draw[rounded corners,<->] (A1-1-1.north)--+(0,5mm)-|(A1-1-5.north);
\matrix[mymatrix, below=5mm of A1] (A2) {|[label=left:$A$]|1&|[fill=violet!30]|2&4&6&5&3\\1&2&3&4&5&6\\};
\draw[rounded corners,<->] ([xshift=-2mm]A2-1-2.north)--+(0,5mm)-|([xshift=2mm]A2-1-2.north);
\end{tikzpicture}
\end{document}
答案2
这是另一个开始。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[yscale=.6]
\begin{scope}
\fill[magenta] (0,0) rectangle +(1,1);
\fill[green] (4,0) rectangle +(1,1);
\draw (0,0) grid (6,1);
\foreach \i/\itext/\itextb in
{1/5/1,2/2/2,3/4/3,4/6/4,5/1/5,6/3/6}
\path (\i-.5,.5) node{\itext} +(-90:1) node{\itextb};
\draw[stealth-stealth,rounded corners]
(.5,1)--++(90:.5)--++(0:4)--++(-90:.5);
\path (0,1) node[left]{$A$};
\end{scope}
\begin{scope}[yshift=-2.5cm]
\fill[magenta] (1,0) rectangle +(1,1);
\draw (0,0) grid (6,1);
\foreach \i/\itext/\itextb in
{1/1/1,2/2/2,3/4/3,4/6/4,5/5/5,6/3/6}
\path (\i-.5,.5) node{\itext} +(-90:1) node{\itextb};
\draw[stealth-stealth,rounded corners]
(1.25,1)--++(90:.5)--++(0:.5)--++(-90:.5);
\path (0,1) node[left]{$A$};
\end{scope}
\end{tikzpicture}
\end{document}