5. In the sequence $\left\{a_{n}\right\}$, $a_{1}=1, a_{n+1}=1+\frac{2}{a_{n}}(n=1,2, \cdots)$, then $a_{n}=$ $\qquad$
$a_{n+1}=1+\frac{2}{a_{n}}=\frac{a_{n}+2}{a_{n}}$, the fixed point equation is $x=\frac{x+2}{x} \Rightarrow x=-1,2$.
Then $a_{n+1}+1=\frac{2 a_{n}+2}{a_{n}}, a_{n+1}-2=\frac{-a_{n}+2}{a_{n}} \Rightarrow \frac{a_{n+1}+1}{a_{n+1}-2}=-2 \cdot \frac{a_{n}+1}{a_{n}-2}$,
thus $\frac{a_{n}+1}{a_{n}-2}=\frac{a_{1}+1}{a_{1}-2} \cdot(-2)^{n-1}=(-2)^{n}$, so $a_{n}=2+\frac{3}{(-2)^{n}-1}\left(n \in \mathbf{N}^{*}\right)$.