How can I construct a continuous function $f$ satisfying that $f|_{\mathbb{Q}}$ is an injection and $f|_{\mathbb{R-Q}}$ is not an injection? How can I construct a continuous function $f:\mathbb{R}\rightarrow \mathbb{R}$ satisfying that $f|_{\mathbb{Q}}$ is an injection and $f|_{\mathbb{R-Q}}$ is not an injection? Can it be constructed?
I was troubled by the problem that if I add the condition $f(\mathbb{Q})\subset \mathbb{Q}$, whether the function can be constructed.
If I let $f(a)=f(b)$ where $a,b \in \mathbb{R-Q}$, and tried to construct a function satisfying that all the rational numbers in the neighborhoods of $a$ and $b$ have different function value. Then I don’t know how to  maintain the continuity of $f$.
 A: For example
$$f(x)=\begin{cases}
\sqrt2\cdot x,\space x\geq 0\\
|x|, \space x<0\\
\end{cases}$$
is injective on $\mathbb Q$ but $f(-\sqrt 6)=\sqrt 6=\sqrt2\cdot\sqrt3=f(\sqrt 3)$.
$\textbf{Edit:}$ This is an answer to the original posed question without the requirement $f(\mathbb Q)\subseteq \mathbb Q$. 
A: Let $(q_n)$ be an enumeration of the rationals and $a,b\in\mathbb R-\mathbb Q$ with $a\neq b$. We will inductively construct a sequence of continous functions $f_n:\mathbb R\to\mathbb R$ such that for all $n\in\mathbb N$

  
*
  
*$f_n(a)=f_n(b)$ and $f_n(q_n)\in\mathbb Q$
  
*$\|f_{n+1}-f_n\|_\infty=\sup_{x\in\mathbb R}|f_{n+1}(x)-f_n(x)|\leq\frac 1 {2^{n+1}}$ 
  
*$f_k(q_k)=f_n(q_k)$ and $f_k(q_k)\neq f_n(q_n)$ for all $k<n$

$\textbf{construction:}$
For each $\varepsilon\geq 0$ and $x\in\mathbb R$ choose a little continous help function   $\phi_\varepsilon ^x:\mathbb R\to[0,\varepsilon]$  which satisfies $\phi_\varepsilon ^x(x)=\varepsilon$ and $\phi_\varepsilon ^x(t)=0$ for $t\notin [x-\varepsilon,x+\varepsilon]$ (for example $\phi_\varepsilon ^x(t)=\varepsilon-|t-x|$ for $t\in[x-\varepsilon,x+\varepsilon]$).
Now let $f_0$ be your favourite continous function with $f_0(a)=f_0(b)$ and assume $f_1,\dots,f_{n-1}$ are already constructed. Find $\varepsilon\in [0,\frac 1 {2^n}]$ such that $a,b,q_1,\dots,q_{n-1}\notin [q_{n}-\varepsilon,q_{n}+\varepsilon]$ and $f_{n-1}(q_n)+\varepsilon\in\mathbb Q\setminus \{f_1(q_1),\dots, f_{n-1}(q_{n-1})\}$ and define $f_n=f_{n-1}+\phi_\varepsilon ^{q_n}$. This finishes the construction. $\square $
$\textbf{definition of f:}$
Now we define $f(x)=\lim f_n(x)$. This is possible since for each $x$ $(f_n(x))$ is a cauchy sequence and $\mathbb R$ is complete. Using 2. we see that $(f_n)$ converges uniformly to $f$ so by the Uniform limit theorem $f$ is continous. Furthermore we have $f(q_n)=f_n(q_n)\in\mathbb Q$ and by 3. $f$ is injective on $\mathbb Q$. Finally  $f(a)=f(b)$ by 1. so $f$ is not injective on $\mathbb R-\mathbb Q$.
