doubly-linked-list.tex 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage{tikz}
  5. \usetikzlibrary{calc,shapes.multipart,chains,arrows,positioning}
  6. \tikzset{
  7. squarecross/.style={
  8. draw, rectangle,minimum size=18pt, fill=orange!80,
  9. inner sep=0pt, text=black,
  10. path picture = {
  11. \draw[black]
  12. (path picture bounding box.north west) --
  13. (path picture bounding box.south east)
  14. (path picture bounding box.south west) --
  15. (path picture bounding box.north east);
  16. }
  17. }
  18. }
  19. \begin{document}
  20. \begin{preview}
  21. \begin{tikzpicture}[
  22. list/.style={
  23. very thick, rectangle split,
  24. rectangle split parts=3, draw,
  25. rectangle split horizontal, minimum size=18pt,
  26. inner sep=5pt, text=black,
  27. rectangle split part fill={blue!20, red!20, blue!20}
  28. },
  29. ->, start chain, very thick
  30. ]
  31. \node[list,on chain] (A) {\nodepart{second} 12};
  32. \node[list,on chain] (B) {\nodepart{second} 99};
  33. \node[list,on chain] (C) {\nodepart{second} 37};
  34. \node[squarecross] (D) [right=of C] {};
  35. \node[squarecross] (E) [left= of A] {};
  36. \path[*->] let \p1 = (A.three), \p2 = (A.center) in (\x1,\y2) edge [bend left] ($(B.one)+(0,0.2)$);
  37. \path[*->] let \p1 = (B.three), \p2 = (B.center) in (\x1,\y2) edge [bend left] ($(C.one)+(0,0.2)$);
  38. \draw[*->] let \p1 = (C.three), \p2 = (C.center) in (\x1,\y2) -- (D);
  39. \draw[*->] ($(A.one)+(0.2,0.1)$) -- (E);
  40. \path[*->] ($(B.one)+(0.1,0.1)$) edge [bend left] ($(A.three)+(0,-0.05)$);
  41. \path[*->] ($(C.one)+(0.1,0.1)$) edge [bend left] ($(B.three)+(0,-0.05)$);
  42. \end{tikzpicture}
  43. \end{preview}
  44. \end{document}