http://forcecore.tistory.com/1017
그리고 이것 저것 뜯어 고쳐서 다음과 같은 코드를 만들었다.
%%%%%%%%%%%%%%%%%%%%%%%%%%\def\sz{6mm}
\tikzstyle{block}
= [draw, fill=black!10, rectangle,
minimum height=\sz, minimum width=\sz]
\tikzstyle{darkblock}
= [draw, fill=black!40, rectangle,
minimum height=\sz, minimum width=\sz]
\tikzstyle{index}
= [draw=none, fill=none, font=\tiny, inner sep=0pt]
\newcounter{myind}
%%%%%%%%%%
\newcommand{\myarray}[2]{
\def\pivot{#1}
\def\arr{#2}
%\node[plain] {A};
\setcounter{myind}{0}
\foreach \item in \arr
{
\addtocounter{myind}{1}
\if\item\pivot
\node[darkblock] at (\themyind*\sz,0) {\item};
\else
\node[block] at (\themyind*\sz,0) {\item};
\fi
\node[index] at (\themyind*\sz,0.65*\sz) {\themyind};
% good positioning is difficult T.T;
}
}
%%%%%%%%%%
\newcommand{\myarrow}{
\node[single arrow, draw, fill=black!40, minimum width=0.15cm, minimum height=1.2cm] {};
}
%%%%%%%%%%
이제
\myarray{9}{3, 2, 9, 0, 7, 5, 4, 8, 6, 1}라고 적으면 9를 pivot으로 하는 array가 그려진다.
다음과 같이 사용해도 된다.
\newcommand{\myarrayx}[4]{
\begin{tikzpicture}
\myarray{#2}{#3}
\end{tikzpicture}
&
\begin{tikzpicture}
\myarrow
\end{tikzpicture}
&
\begin{tikzpicture}
\myarray{#2}{#4}
\end{tikzpicture} \\
}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{mysubfigcounter}
\setcounter{mysubfigcounter}{1}
\newcommand{\mysubfigcap}{
\multicolumn{3}{c}{\footnotesize (\alph{mysubfigcounter})} \\\\
\addtocounter{mysubfigcounter}{1}
}
\begin{figure}[ht]
\centering
\begin{tabular}{rcl}
\myarrayx{1}{9}{3, 2, 9, 0, 7, 5, 4, 8, 6, 1}{3, 2, 0, 7, 5, 4, 8, 6, 1, 9}
\mysubfigcap
\myarrayx{2}{8}{3, 2, 0, 7, 5, 4, 8, 6, 1}{3, 2, 0, 7, 5, 4, 6, 1, 8}
\mysubfigcap
\end{tabular}
\end{figure}
결과는
아 위에 결과는 틀린 결과이다. ㅠㅠ