Fixed the null pointer dereference issue in getTopAndPop() function