Use namespace std and use nullptr instead of NULL in a couple of places
use range for-loop