Characterization of nonsmooth quasiconvex and pseudoconvex functions