-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListIterator.cpp
53 lines (45 loc) · 950 Bytes
/
ListIterator.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
#include "ListIterator.h"
#include "SortedIndexedList.h"
#include <iostream>
using namespace std;
ListIterator::ListIterator(const SortedIndexedList& list) : list(list) {
this->index = list.head;
}
//Complexitate:
//best case: Θ(1)
//worst case: Θ(1)
//average case: Θ(1)
void ListIterator::first(){
this->index = list.head;
}
//Complexitate:
//best case: Θ(1)
//worst case: Θ(1)
//average case: Θ(1)
void ListIterator::next(){
if(valid()){
this->index = list.elements[this->index].next;
}else{
throw exception();
}
}
//Complexitate:
//best case: Θ(1)
//worst case: Θ(1)
//average case: Θ(1)
bool ListIterator::valid() const{
if(index != -1)
return true;
return false;
}
//Complexitate:
//best case: Θ(1)
//worst case: Θ(1)
//average case: Θ(1)
TComp ListIterator::getCurrent() const{
if(valid()){
return list.elements[this->index].info;
}else{
throw exception();
}
}