When does the squeeze theorem fail? In introduction real analysis course, we have squeeze theorem which is: let $f,g$ and $h$ are functions from $\mathbb R$ to $\mathbb R$ and $f(x)\leq g(x)\leq h(x)$ such that $\lim\limits_{x\to a} f(x)= \lim\limits_{x\to a} h(x)=L$, $L\in\Bbb R$, then $\lim\limits_{x\to a} g(x)=L.$ In this course, we consider $\Bbb R$ with usual metric, that is, $(\Bbb R, d(x,y)=|x-y|)$.
The question came to my mind is that Can we find a system such that  the squeeze theorem will not be correct that, means,  $f,g$ and $h$ are functions from $\mathbb X$ to $\mathbb Y$ and $f(x)\leq g(x)\leq h(x)$ such that $\lim\limits_{x\to a} f(x)= \lim\limits_{x\to a} h(x)=L$, $L\in\Bbb Y$, but  $\lim\limits_{x\to a} g(x)\neq L,$ $X$ and $Y$ can be any sets, that is, $X$ and $Y$ might not be subsets from $\Bbb R.$
Any idea
 A: If you order the rationals by enumerating them $q_1,q_2,\dots$ and say $q_i\leq_r q_j$ iff $i\leq j,$ then the squeeze theorem won't apply to the rationals under this order.
To find a counter-example in this case is a little wordy, so I'll skip that for the second example.

Another example is $\mathbb R^2$ with the usual metric, but with the dictionary ordering, $(x,y)\leq_d (x',y')$ if $x<x'$ or if $x=x'$ and $y\leq y'.$
Then $f,g:\mathbb R^+\to\mathbb R^2$ defined as $g(x)=(0,x)$ and $f(x)=(0,-x)$ as $x\to 0$ converge to the same value, but we can define $h(x)=(-1,x)$ satisfies $f(x)\leq h(x)\leq g(x).$ Here $f(x),g(x)\to (0,0)$ but $h(x)\to(-1,0).$
In fact, I believe we can show there is no total order on $\mathbb R^2$ which will work for the squeeze theorem. But the natural partial order: $$(x,y)\leq (x',y')\iff x\leq x'\land y\leq y'$$ will work.

A third example is the set $\mathbb Q$ of rational numbers, with the standard order, but with the $p$-adic metric. Then $a_n=p^{2n}$ and $b_n=p^{2n+1}$ both converge to $0,$ but $c_n=a_n+1$ converges to $1$ and $d_n=a_n+p+(-1)^n$ doesn't converge at all.

If you have a metric space $(X,d)$ and a partial ordering $\leq$ on $X,$ such that for all $x\leq y\leq z$ in $X,$ $$d(x,z)\geq \min(d(x,y),d(y,z))\tag 1$$ then the squeeze theorem applies.
This essentially means that being between two elements in the partial order means that the point is closer to one of the endpoints than the endpoints are to each other. In most cases, we actually have $\max$ true in $(1)$, not just $\min.$
This is because $\lim_{x\to a} f(x)=L$ is the same as saying $\lim_{x\to a} d(f(x),L)=0.$
When $f(x)\to L$ and $g(x)\to L,$ we get $$\max(d(f(x),L),d(g(x),L))\to0$$ and $$d(f(x),g(x))\leq d(f(x),L)+d(L,g(x))\to 0$$
And if $f(x)\leq h(x)\leq g(x)$ then $$\begin{align}d(h(x),L)&\leq d(h(x),f(x))+d(f(x),L)\\&\leq d(h(x),f(x))+\max(d(f(x),L),d(g(x),L))\end{align}$$
and similarly: $$d(h(x),L)\leq d(h(x),g(x))+\max(d(f(x),L),d(g(x),L))$$
So $$\begin{align}d(h(x),L)&\leq\min (d(h(x),f(x)),d(h(x),g(x)))+\max(d(f(x),L),d(g(x),L))\\
&\leq d(f(x),g(x))+\max(d(f(x),L),d(g(x),L))\to 0
\end{align}$$
You can loosen the restrictions even more. If $F:\mathbb R^{\geq0}\to\mathbb R^{\geq0}$ is defined so that $F(0)=0$ and $F$ is continuous at $0,$ and:
$$ \min(d(x,y),d(y,z))\leq F(d(x,z))\tag{1'}$$
when $x\leq y\leq z,$ then we get the squeeze theorem.

The fundamental reason that the squeeze theorem works for the reals is related to something called the order topology. Given any totally-ordered set, $(Y,\leq)$ we can define a topology with basis the open intervals $(y_1,y_2)=\{y\in Y:y_1<y<y_2\}.$ (It's a little more complicated than that when the order has maximal or minimal elements.)
Essentially, the squeeze theorem is about convergent limits in the order topology, not a metric topology. It is true in all totally-ordered spaces under the order topology.
Partial orders sometimes have a related topology, too, but not always.
For the squeeze theorem to apply to an ordered metric space, we'd want that the open intervals in the order are all open sets in the metric topology. That is, every open interval $(x,y)$ is an open subspace in the metric.
You might also need that every open ball in the metric around $x$ contains an open interval in the order containing $x.$ If so, then the open intervals become a basis for the topology.
These might not be necessary conditions, but it is intuitively the relationship we need to deduce the squeeze theorem.
The first two counterexamples I gave above are total order examples where the order topology is strictly bigger than the metric topology.
In the third ($p$-adic) example, the order topology is almost entirely different from the metric topology - open intervals in $\mathbb Q$ are never open sets in the $p$-adic topology, and open balls around $x$ never contains an open interval containing $x.$
