s1
and s2
.push
operation, push the element onto s1
.pop
operation, if s2
is empty, transfer all elements from s1
to s2
by popping from s1
and pushing onto s2
. Then pop the top of s2
.s2
is not empty, pop the top of s2
directly.peek
operation, if s2
is empty, transfer all elements from s1
to s2
and return the top of s2
. If s2
is not empty, return the top of s2
.empty
operation, check if both s1
and s2
are empty. If both are empty, the queue is empty.