18. Let $a \leq 2$, find the maximum and minimum values of $y=(x-2)|x|$ on $[a, 2]$.

---

The translation is provided as requested, maintaining the original format and line breaks.
Solution: When $x \leq 0, y=-(x-1)^{2}+1$,
When
$$
x>0, y=(x-1)^{2}-1 \text {, }
$$

From
this
we know
$$
y_{\max }=0
$$
. 10 points

When $1 \leq a \leq 2, y_{\min }=a^{2}-2 a$;
When $1-\sqrt{2} \leq a<1, y_{\min }=-1$;
When
$$
a<1-\sqrt{2}, y_{\min }=-a^{2}+2 a
$$
$\qquad$ 17 points