Usually anything that looks like a matrix can be made more easily with a TikZ matrix. And usually a TikZ matrix is easier than the cumbersome placement of single nodes.
1. The picture from the startpost:

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[font=\footnotesize\sffamily,
>=stealth,
]
\matrix (m) [matrix of nodes, nodes in empty cells,
nodes={draw, %thick,
%inner sep=0pt, outer sep=0pt,
%minimum width=1.9em,
text height=\ht\strutbox,
text depth=\dp\strutbox,
text width =1.5\ht\strutbox,
align=center, anchor=center,
},
column sep=1em, row sep=-\pgflinewidth,
Fill/.style 2 args={row #1 column #2/.style={nodes={fill=cyan!66}}},
Fill/.list={ {5}{2}, {5}{3} },
row 1/.style={nodes={draw=none} },
column 1/.style={column sep=2em,
nodes={align=right, draw=none, text width=1cm} },
%
row 2 column 1/.style={nodes={xshift=-2mm}},
%
column 5/.style={nodes={draw=none} },
row 2 column 5/.style={nodes={draw} },
%
row 2/.style={row sep=1.5em, },
%
column 4/.style={column sep=1.75em, },
]{
& & & & tail \
mapping & 0 & 4 & 10 & 10 \
value & -16 & -16 & -16 & \
point & 3 & 10 & 15 & \
next & 4 & 10 & / & \
%1 & 2 & 3 & 4 & 5 \
};
% Annotations:
\foreach \col in {2,...,4}{
\draw[->] (m-2-\col) -- (m-3-\col); }
\draw[->] (m-2-5) -- (m-2-4);
\foreach \row in {3,...,5}{
\draw[shorten >=2pt] (m-\row-1) -- (m-\row-2); }
\draw[shorten >=1em] (m-2-1) -- (m-2-2);
\draw[densely dashed] ([shift={(-0.5em,0.5em)}]m-2-2.north west) rectangle ([shift={(0.5em,-0.5em)}]m-2-\lastcolP.south east);
\end{tikzpicture}
\end{document}
2. With variable numbers of rows and columns:
There is no key like row last/.style=... so you need to create them and then use some tricks due to the expanding order:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\makeatletter
\tikzset{store number of columns in/.style={execute at end matrix={
\xdef#1{\the\pgf@matrix@numberofcolumns}}},
store number of rows in/.style={execute at end matrix={
\xdef#1{\the\pgfmatrixcurrentrow}}}}
\makeatother
\begin{document}
% Wrong start values
\def\lastrow{1}
\def\lastcol{1}
\def\lastcolP{1}
\newcommand\mymatrix{%%%
\begin{tikzpicture}[font=\footnotesize\sffamily,
>=stealth,
]
\matrix (m) [matrix of nodes, nodes in empty cells,
store number of columns in=\lastcol,
store number of rows in=\lastrow,
ampersand replacement=&,
nodes={draw, %thick,
inner sep=0pt, outer sep=0pt,
minimum width=1.9em,
text height=\ht\strutbox,
text depth=\dp\strutbox,
text width =1.5\ht\strutbox,
align=center, anchor=center,
},
column sep=1em, row sep=-\pgflinewidth,
]{
& & & & & tail \
mapping& 0 & 4 & new & 1 & 10 \
value & -16 & -16 & new & -16 & \
point & 3 & 10 & new & 15 & \
new & new & new & new & new & \
new & new & new & new & new & \
new & new & new & new & new & \
next & 4 & 10 & new & / & \
%1 & 2 & 3 & 4 & 5 & 6 \
};
%
% Annotations:
\foreach \col in {2,...,\lastcolP}{
\draw[->] (m-2-\col) -- (m-3-\col); }
\draw[->] (m-2-\lastcol) -- (m-2-\lastcolP);
\foreach \row in {3,...,\lastrow}{
\draw[shorten >=2pt, shorten <=2pt] (m-\row-1) -- (m-\row-2); }
\draw[shorten >=0.7em, shorten <=3pt] (m-2-1) -- (m-2-2);
\draw[densely dashed] ([shift={(-0.5em,0.5em)}]m-2-2.north west) rectangle ([shift={(0.5em,-0.5em)}]m-2-\lastcolP.south east);
\end{tikzpicture}
}%%%
\newsavebox{\mybox}
\savebox{\mybox}{\mymatrix}
\section{Wrong}
\mymatrix
\section{Still Wrong}
\usebox{\mybox} \par
Last col is: \lastcol. Last row is \lastrow.
\pgfmathtruncatemacro\lastcolP{\lastcol-1}
\tikzset{
store number of columns in=\lastcol,
store number of rows in=\lastrow,
Fill/.style 2 args={row #1 column #2/.style={nodes={fill=cyan!44}}},
Fill/.list={ {\lastrow}{2}, {\lastrow}{3} },
row 1/.style={nodes={draw=none} },
column 1/.style={column sep=2em,
nodes={align=right, draw=none, text width=1cm} },
%
row 2 column 1/.style={nodes={xshift=-2mm}},
%
column \lastcol/.style={nodes={draw=none} },
row 2 column \lastcol/.style={nodes={draw} },
%
row 2/.style={row sep=1.5em, },
%
column \lastcolP/.style={column sep=1.75em, },
}
\section{Correct}
\savebox{\mybox}{\mymatrix}
\usebox{\mybox}
\end{document}
squarestyle defined? – Alan Munn Nov 01 '20 at 19:15dep(with color) andcli(without color) ; their aliases' might be confusing because I haven't changed them from the original example – alper Nov 01 '20 at 19:17squareisn't defined. – Alan Munn Nov 01 '20 at 19:19