Change List::remote(const T&) to return a bool

It now indicates whether the removal took place or not, depending
on whether a matching element was found in the list.
This commit is contained in:
Jon Siwek 2019-07-15 18:48:24 -07:00
parent 7ccf3c0a69
commit ee95fd2801

View file

@ -273,13 +273,18 @@ public:
entries[num_entries++] = a; entries[num_entries++] = a;
} }
T remove(const T& a) // delete entry from list bool remove(const T& a) // delete entry from list
{ {
int i; for ( int i = 0; i < num_entries; ++i )
for ( i = 0; i < num_entries && a != entries[i]; ++i ) {
; if ( a == entries[i] )
{
remove_nth(i);
return true;
}
}
return remove_nth(i); return false;
} }
T remove_nth(int n) // delete nth entry from list T remove_nth(int n) // delete nth entry from list