Home

Popfront

Popfront, often written as pop_front, is an operation on a container that removes the first element. Depending on the API, the operation may return the removed element or may discard it; in the latter case, the value may need to be retrieved before the removal.

Common implementations include queues, deques, and linked lists, where pop_front is typically performed in constant time.

Usage examples and behavior vary by language and library. In a typical queue, you may check that

Notes and related concepts: pop_front is often paired with push_front or push_back to model double-ended queues.

See also: push_front, push_back, dequeue, shift, removeFirst.

By
contrast,
removing
the
first
element
from
arrays
or
vectors
usually
requires
shifting
or
reallocation,
resulting
in
linear
time
(O(n))
in
the
size
of
the
container
and
making
frequent
front
removals
less
efficient.
it
is
non-empty,
inspect
the
front
element,
and
then
remove
it.
Pseudo-code:
if
not
q.is_empty():
v
=
q.front();
q.pop_front();
In
some
libraries,
pop_front
returns
the
removed
value
(for
example,
Rust’s
VecDeque.pop_front()),
while
others
require
a
separate
front
access
before
removal
(as
in
C++'s
deque,
where
front()
can
be
used
before
pop_front()).
In
JavaScript,
a
similar
effect
is
achieved
with
shift(),
which
removes
the
first
element
from
an
array.
When
designing
performance-critical
code,
front
removals
are
best
performed
on
deques
or
linked
structures
rather
than
on
arrays
or
vectors.