$D^+f(0)=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{f(t)-f(0)}{t}=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{t\sin \frac1t}{t}=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\sin\frac{1}{t}$ Now no matter how small $h$ gets, there always exist a point $t$ in $(0,h]$ so that $\sin\frac{1}{t}=+1$ (take $t=\frac{1}{n\pi +\frac{\pi}{2}}$ for sufficiently large $n$) Therefore, $D^+f(0)=+1$. Similarly $D^{-}f(0)=-1$.
At all points $x\neq 0$, $x\sin\frac{1}{x}$ is differentiable and as thus $D^+f(x)=D^-f(x)=f^{\prime}(x)=\sin \frac{1}{x}-\frac{1}{x}\cos\frac1x$
For $g$: If $x\in \mathbb{Q}$,$D^+g(x)=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{g(x+t)-g(x)}{t}=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{\chi_{\mathbb{Q}}(x+t)-1}{t}$ Now $\frac{\chi_{\mathbb{Q}}(x+t)-1}{t}=\begin{cases} 0&\mbox{if } t\in \mathbb{Q}\\ \frac{-1}{t}&\mbox{if } t\notin \mathbb{Q}\end{cases}$ The supremum is achieved when $t<0$ and $t\notin \mathbb{Q}$ which means $0<-t\le h\Rightarrow -h\le t<0$. No matter how small $h$ gets there always exists a point $t\in [-h,0)\cap \mathbb{Q}^c$ (density argument) and so $D^+g(x)=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{\chi_{\mathbb{Q}}(x+t)-1}{t}=\lim_{h \to 0}\sup\limits_{-h\le t<0}\frac{-1}{t}=+\infty$ All other cases are done in the same spirit