singly-linked-list.tex 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage{tikz}
  5. \usetikzlibrary{calc,shapes.multipart,chains,arrows}
  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=2, draw,
  25. rectangle split horizontal, minimum size=18pt,
  26. inner sep=4pt, text=black,
  27. rectangle split part fill={red!20, blue!20}
  28. },
  29. ->, start chain, very thick
  30. ]
  31. \node[list,on chain] (A) {12};
  32. \node[list,on chain] (B) {99};
  33. \node[list,on chain] (C) {37};
  34. \node[squarecross] (D) [right=of C] {};
  35. \draw[*->] let \p1 = (A.two), \p2 = (A.center) in (\x1,\y2) -- (B);
  36. \draw[*->] let \p1 = (B.two), \p2 = (B.center) in (\x1,\y2) -- (C);
  37. \draw[*->] let \p1 = (C.two), \p2 = (C.center) in (\x1,\y2) -- (D);
  38. \end{tikzpicture}
  39. \end{preview}
  40. \end{document}