Check return value when peeking linked lists
This commit is contained in:
@@ -168,7 +168,8 @@ int SingleList::peek() const
|
||||
if (!isEmpty())
|
||||
std::cout << "[" << head->data << "] is at the top of our list\n";
|
||||
else std::cout << "Nothing to peek, our list is empty...\n";
|
||||
return head->data;
|
||||
// If the list has data we return it, otherwise we return the smallest possible int (error)
|
||||
return (!isEmpty()) ? head->data : INT32_MIN;
|
||||
}
|
||||
|
||||
/** print
|
||||
|
||||
Reference in New Issue
Block a user