-
Notifications
You must be signed in to change notification settings - Fork 0
/
BagIterator.cpp
55 lines (47 loc) · 1.45 KB
/
BagIterator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <exception>
#include "BagIterator.h"
#include "Bag.h"
using namespace std;
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
BagIterator::BagIterator(const Bag& c): bag(c)
{
this->index = 0;
this->start=1;
this->pace=2;
}
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
void BagIterator::first() {
this->index = 0;
}
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
void BagIterator::next() {
if(this->index < this->bag.nrElemsPositions)
this->index+=1;
else
throw exception();
}
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
bool BagIterator::valid() const {
if(this->index < this->bag.nrElemsPositions)
return true;
return false;
}
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
TElem BagIterator::getCurrent() const
{
if(valid()){
return this->bag.liste[this->bag.positions[this->index]];
}
else{
throw exception();
}
}
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
void BagIterator::first_ra() {
this->index=this->start;
}
//best case: θ(1) worst case:θ(1) average case:θ(1) allgemeine Komplexitat:θ(1)
void BagIterator::next_ra() {
if(this->index + this->pace < bag.nrElemsPositions && this->index +this->pace > this->start)
this->index+=this->pace;
}