Implements visit function for adding nodes to frontier