Hello neelpatel89
Here's the proof, then, using the structure in my earlier post.
(a) Consider $\displaystyle p, q \in \mathbb{Z}$, where $\displaystyle f(p) = f(q)$
First: $\displaystyle p\ge 0$ and $\displaystyle q \ge 0 $$\displaystyle \Rightarrow 2p = 2q$
$\displaystyle \Rightarrow p = q$
Then $\displaystyle p < 0$ and $\displaystyle q < 0$ $\displaystyle \Rightarrow -(2p+1) = -(2q+1)$
$\displaystyle \Rightarrow p = q$
Finally, we note that if $\displaystyle p \ge 0, f(p)$ is even and if $\displaystyle q < 0$, $\displaystyle f(q)$ is odd. So $\displaystyle f(p) \ne f(q)$ if $\displaystyle p$ and $\displaystyle q$ have different signs.
So for all $\displaystyle p,q \in \mathbb{Z}, f(p) = f(q) \Rightarrow p = q$, and therefore $\displaystyle f$ is injective.
(b) Consider $\displaystyle m \in \mathbb{N} \cup \{0\}$.
Then if $\displaystyle m$ is even, $\displaystyle m = 2n$ for some $\displaystyle n \in\mathbb{N} \cup \{0\}$. Also $\displaystyle m \ge 0$. So $\displaystyle n \ge 0$. Therefore $\displaystyle f(n) = m$ for some $\displaystyle n \in \mathbb{Z}$.
If $\displaystyle m$ is odd, $\displaystyle m \ge 1$ and therefore $\displaystyle m = 2n-1$ for some $\displaystyle n > 0$
$\displaystyle \Rightarrow m = -(2(-n)+1)$, where $\displaystyle (-n) < 0$
$\displaystyle \Rightarrow m = f(-n)$
Therefore for all $\displaystyle m \in \mathbb{N} \cup \{0\}$, there is an $\displaystyle n \in \mathbb{Z}$ such that $\displaystyle f(n) = m$. Therefore $\displaystyle f$ is surjective.
Grandad