List erweitert

This commit is contained in:
madmaurice 2015-11-11 20:17:13 +01:00
parent 2836fceedc
commit cdc4a6f4f2

View file

@ -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<T>::insert(T e) {
return true;
}
template <class T>
bool List<T>::find(T e) {
if(!this->find_first()) return false;
do {
if(this->retrieve() == e){
return true;
}
} while(this->find_next());
return false;
}
template <class T>
bool List<T>::find_prior() {
if(this->empty()) return false;
@ -108,6 +122,13 @@ bool List<T>::find_first() {
return true;
}
template <class T>
bool List<T>::find_last() {
if(!this->find_first()) return false;
while(this->find_next());
return true;
}
template <class T>
T List<T>::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();