Check return value when peeking linked lists

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

View File

@ -187,7 +187,8 @@ int CircleDoubleList::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->data;
// If the list has data we return it, otherwise we return the smallest possible int (error)
return (!isEmpty()) ? tail->data : INT32_MIN;
}
/** print

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

View File

@ -168,7 +168,8 @@ int DoubleList::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

View File

@ -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