Skip to content

Commit

Permalink
Refactor List operator[] to prevent compiler warnings (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaOrtner authored Aug 24, 2024
2 parents a7041f3 + a773eb8 commit f5a7ec3
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions core/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,31 +438,23 @@ class List {

Element* I = front();
int c = 0;
while (I) {
if (c == p_index) {
return I->get();
}
while (c < p_index) {
I = I->next();
c++;
}

CRASH_NOW(); // bug!!
return I->get();
}

const T& operator[](int p_index) const {
CRASH_BAD_INDEX(p_index, size());

const Element* I = front();
int c = 0;
while (I) {
if (c == p_index) {
return I->get();
}
while (c < p_index) {
I = I->next();
c++;
}

CRASH_NOW(); // bug!!
return I->get();
}

void move_to_back(Element* p_I) {
Expand Down

0 comments on commit f5a7ec3

Please sign in to comment.