Properly implemented hasNext() method as per Piazza recommendations, which is having a head reference