Check return value when peeking linked lists
This commit is contained in:
parent
60b4042681
commit
6b8435d5f6
|
@ -187,7 +187,8 @@ int CircleDoubleList::peek() const
|
||||||
if (!isEmpty())
|
if (!isEmpty())
|
||||||
std::cout << "[" << tail->next->data << "] is at the top of our list\n";
|
std::cout << "[" << tail->next->data << "] is at the top of our list\n";
|
||||||
else std::cout << "Nothing to peek, our list is empty...\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
|
/** print
|
||||||
|
|
|
@ -191,7 +191,8 @@ int CircleSingleList::peek() const
|
||||||
if (!isEmpty())
|
if (!isEmpty())
|
||||||
std::cout << "[" << tail->next->data << "] is at the top of our list\n";
|
std::cout << "[" << tail->next->data << "] is at the top of our list\n";
|
||||||
else std::cout << "Nothing to peek, our list is empty...\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
|
/** print
|
||||||
|
|
|
@ -168,7 +168,8 @@ int DoubleList::peek() const
|
||||||
if (!isEmpty())
|
if (!isEmpty())
|
||||||
std::cout << "[" << head->data << "] is at the top of our list\n";
|
std::cout << "[" << head->data << "] is at the top of our list\n";
|
||||||
else std::cout << "Nothing to peek, our list is empty...\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
|
/** print
|
||||||
|
|
|
@ -168,7 +168,8 @@ int SingleList::peek() const
|
||||||
if (!isEmpty())
|
if (!isEmpty())
|
||||||
std::cout << "[" << head->data << "] is at the top of our list\n";
|
std::cout << "[" << head->data << "] is at the top of our list\n";
|
||||||
else std::cout << "Nothing to peek, our list is empty...\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
|
/** print
|
||||||
|
|
Loading…
Reference in New Issue