diff --git a/cpp/datastructs/circledoublelist/circledoublelist.cpp b/cpp/datastructs/circledoublelist/circledoublelist.cpp index 767baad..a8c2c16 100644 --- a/cpp/datastructs/circledoublelist/circledoublelist.cpp +++ b/cpp/datastructs/circledoublelist/circledoublelist.cpp @@ -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 diff --git a/cpp/datastructs/circlesinglelist/circlesinglelist.cpp b/cpp/datastructs/circlesinglelist/circlesinglelist.cpp index 0f2390b..9027f3f 100644 --- a/cpp/datastructs/circlesinglelist/circlesinglelist.cpp +++ b/cpp/datastructs/circlesinglelist/circlesinglelist.cpp @@ -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 diff --git a/cpp/datastructs/doublelist/doublelist.cpp b/cpp/datastructs/doublelist/doublelist.cpp index 06df49e..4fd8182 100644 --- a/cpp/datastructs/doublelist/doublelist.cpp +++ b/cpp/datastructs/doublelist/doublelist.cpp @@ -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 diff --git a/cpp/datastructs/singlelist/singlelist.cpp b/cpp/datastructs/singlelist/singlelist.cpp index 52d54bd..e469f53 100644 --- a/cpp/datastructs/singlelist/singlelist.cpp +++ b/cpp/datastructs/singlelist/singlelist.cpp @@ -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