mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-01 17:52:40 +08:00
fix: CodeQL warnings (#1827)
* fix: CodeQL warnings * clang-format and clang-tidy fixes for4d357c46* clang-format and clang-tidy fixes for72322fb7* accept suggestion * clang-format and clang-tidy fixes for9a4dc07cCo-authored-by: David Leal <halfpacho@gmail.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Ayaan Khan <ayaankhan98@gmail.com>
This commit is contained in:
@@ -121,12 +121,10 @@ void list::reverseList() {
|
||||
* @returns the top element of the list
|
||||
*/
|
||||
int32_t list::top() {
|
||||
try {
|
||||
if (!isEmpty()) {
|
||||
return head->val;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "List is empty" << e.what() << '\n';
|
||||
if (!isEmpty()) {
|
||||
return head->val;
|
||||
} else {
|
||||
throw std::logic_error("List is empty");
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -134,16 +132,14 @@ int32_t list::top() {
|
||||
* @returns the last element of the list
|
||||
*/
|
||||
int32_t list::last() {
|
||||
try {
|
||||
if (!isEmpty()) {
|
||||
Node *t = head;
|
||||
while (t->next != nullptr) {
|
||||
t = t->next;
|
||||
}
|
||||
return t->val;
|
||||
if (!isEmpty()) {
|
||||
Node *t = head;
|
||||
while (t->next != nullptr) {
|
||||
t = t->next;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "List is empty" << e.what() << '\n';
|
||||
return t->val;
|
||||
} else {
|
||||
throw std::logic_error("List is empty");
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -164,7 +160,7 @@ int32_t list::traverse(int index) {
|
||||
|
||||
/* if we get to this line,the caller was asking for a non-existent element
|
||||
so we assert fail */
|
||||
assert(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
} // namespace linked_list
|
||||
|
||||
Reference in New Issue
Block a user