LaTeX

TikZ Linked List

알 수 없는 사용자 2009. 4. 18. 16:58
Sparse Matrix 를 그릴 때 이걸 응용하면 된다.
Linked List도 응용 가능.


\begin{tikzpicture}

% size of each node

\def\lg{10mm};

\def\sml{8mm};

% node style definition

\tikzstyle{block} = [

draw, fill=black!10, rectangle,

minimum height=\lg, minimum width=\lg ];

\tikzstyle{sblock} = [

draw, fill=black!10, rectangle,

minimum height=\sml, minimum width=\sml ];

\tikzstyle{plain} = [draw=none,fill=none];

% array element definition

\node[plain] at (0,1) {B};

\foreach \i in {0,...,9}

{

\node[block] at (0,-\i*\lg) {};

\node[plain] at (-0.7,-\i*\lg) { \i };

}

% NULL pointer nodes

\def\gnd{0,9};

\foreach \item in \gnd

{

\node[block] at (0,-\item*\lg) {/};

}

% attached nodes

\def\y{-1};

\node[sblock] at (2,\y) {.13};

\node[sblock] at (2cm+\sml,\y) {};

\node[sblock] at (4cm+\sml,\y) {.16};

\node[sblock] at (4cm+2*\sml,\y) {/};

\def\y{-2};

\node[sblock] at (2,\y) {.20};

\node[sblock] at (2cm+\sml,\y) {/};

\def\y{-3};

\node[sblock] at (2,\y) {.39};

\node[sblock] at (2cm+\sml,\y) {/};

\def\y{-4};

\node[sblock] at (2,\y) {.42};

\node[sblock] at (2cm+\sml,\y) {/};

\def\y{-5};

\node[sblock] at (2,\y) {.53};

\node[sblock] at (2cm+\sml,\y) {/};

\def\y{-6};

\node[sblock] at (2,\y) {.64};

\node[sblock] at (2cm+\sml,\y) {/};

\def\y{-7};

\node[sblock] at (2,\y) {.79};

\node[sblock] at (2cm+\sml,\y) {};

\node[sblock] at (4cm+\sml,\y) {.71};

\node[sblock] at (4cm+2*\sml,\y) {/};

\def\y{-8};

\node[sblock] at (2,\y) {.89};

\node[sblock] at (2cm+\sml,\y) {/};

% pointer indications

\begin{scope}[-latex,thick]

\foreach \i in {-1,...,-8} {

\draw (0,\i) -- (2cm-\sml/2,\i);

}

\draw (2cm+\sml,-1) -- (4cm+\sml/2,-1);

\draw (2cm+\sml,-7) -- (4cm+\sml/2,-7);

\end{scope}

\end{tikzpicture}