\documentclass[tikz,margin=1cm]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{
queue element/.style={
draw,very thin,
minimum width=1cm,minimum height=.1cm,
fill=brown!30,
font=\sffamily\footnotesize
},
>={[scale=0.8]Triangle}
}
\newcommand\x{1}
\newcommand\y{5}
%Enqueue:
\newcommand\m{1}
\newcommand\n{6}
%Dequeue:
\newcommand\s{2}
\newcommand\f{6}
\begin{document}
\begin{tikzpicture}
\scope[yshift=-1cm]
\foreach \i/\name in {\x,...,\y}{
\node[queue element] (\i) at (1*\i,0){\i};
\draw[<-] ([yshift=.2cm]\x.north) -- ++ (0,.5) node[above] {front};
}
\draw[<-] ([yshift=.2cm]\y.north) -- ++ (0,.5) node[above] {rear};
\endscope
%Enqueue:
\scope[yshift=-3cm]
\foreach \i in {\m,...,\n}{
\node[queue element] (\i) at (1*\i,0){\i};
\draw[<-] ([yshift=.2cm]\m.north) -- ++ (0,.5) node[above] {front};
}
\draw[<-] ([yshift=.2cm]\n.north) -- ++ (0,.5) node[above] {rear};
\path (-2.5,0) node[right] {Enqueue:};
\endscope
%Dequeue:
\scope[yshift=-5cm]
\foreach \i in {\s,...,\f}{
\node[queue element] (\i) at (1*\i,0){\i};
\draw[<-] ([yshift=.2cm]\s.north) -- ++ (0,.5) node[above] {front};
}
\draw[<-] ([yshift=.2cm]\f.north) -- ++ (0,.5) node[above] {rear};
\path (-2.5,0) node[right] {Dequeue:};
\endscope
\end{tikzpicture}
\end{document}
If anyone needs this(circled red) just put draw outside of foreach for last elemen and 1st in foreach(like i did in my code):



\the\numexprdoes nothing useful where you use it; it would do if you need to do arithmetic with\xand friends. – egreg Dec 29 '22 at 17:35\i=\sand\i=\f. You could also give your nodes proper names, say(i\i), and then you can reference them with(i\s)and(i\f). Thechainslibrary could make this even easier by providing(chain-begin)and(chain-end)names for the first and last node in a chain. And thepinoption might make it even easier to add an edge to a node. – Qrrbrbirlbel Dec 29 '22 at 18:32