Check return value when peeking linked lists

This commit is contained in:
2020-06-04 08:48:45 -04:00
parent 60b4042681
commit 6b8435d5f6
4 changed files with 8 additions and 4 deletions

View File

@@ -191,7 +191,8 @@ int CircleSingleList::peek() const
if (!isEmpty())
std::cout << "[" << tail->next->data << "] is at the top of our list\n";
else std::cout << "Nothing to peek, our list is empty...\n";
return tail->next->data;
// If the list has data we return it, otherwise we return the smallest possible int (error)
return (!isEmpty()) ? tail->next->data : INT32_MIN;
}
/** print