diff --git a/list.cpp b/list.cpp index bb33698..67259a8 100644 --- a/list.cpp +++ b/list.cpp @@ -20,6 +20,8 @@ class List { bool find_first(); bool find_next(); bool find_prior(); + bool find_last(); + bool find(T e); bool full(); bool empty(); T retrieve(); @@ -62,6 +64,18 @@ bool List::insert(T e) { return true; } + +template +bool List::find(T e) { + if(!this->find_first()) return false; + do { + if(this->retrieve() == e){ + return true; + } + } while(this->find_next()); + return false; +} + template bool List::find_prior() { if(this->empty()) return false; @@ -108,6 +122,13 @@ bool List::find_first() { return true; } +template +bool List::find_last() { + if(!this->find_first()) return false; + while(this->find_next()); + return true; +} + template T List::retrieve() { assert(!this->empty()); @@ -127,11 +148,26 @@ int main( int argc, char *argv[] ) { l.insert(i); } assert(i == 20); - assert(l.find_first()); - while(l.find_next()) { - cout << l.retrieve() << endl; - } + // Delete half + l.find_first(); + for(i = 0; i < 10; i++) l.remove(); + + // Delete 14 + assert(l.find(14)); + assert(l.remove()); + assert(!l.find(14)); + + assert() + + // Show values + assert(l.find_first()); + do { + cout << l.retrieve() << endl; + } while(l.find_next()); + + + // Delete all assert(l.find_first()); while(!l.empty()) l.remove();