From ee95fd2801a4f33a2d1de0ec8dd63d7783e33be9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 15 Jul 2019 18:48:24 -0700 Subject: [PATCH] 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. --- src/List.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/List.h b/src/List.h index 0540c56354..bbd2bc9673 100644 --- a/src/List.h +++ b/src/List.h @@ -273,13 +273,18 @@ public: 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 ( i = 0; i < num_entries && a != entries[i]; ++i ) - ; + for ( int i = 0; i < num_entries; ++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