fix: CodeQL warnings (#1827)

* fix: CodeQL warnings

* clang-format and clang-tidy fixes for 4d357c46

* clang-format and clang-tidy fixes for 72322fb7

* accept suggestion

* clang-format and clang-tidy fixes for 9a4dc07c

Co-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:
2kindsofcs
2021-11-08 02:49:33 +09:00
committed by GitHub
parent b98dcdfd08
commit e64e3df18f
7 changed files with 65 additions and 66 deletions

View File

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