School Commit Init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include "SMIterator.h"
|
||||
#include "SortedMap.h"
|
||||
#include <exception>
|
||||
|
||||
using namespace std;
|
||||
|
||||
SMIterator::SMIterator(const SortedMap& m) : map(m){
|
||||
//Complexity: O(1)
|
||||
this->current = this->map.head;
|
||||
|
||||
}
|
||||
|
||||
void SMIterator::first(){
|
||||
//Complexity: O(1)
|
||||
this->current = this->map.head;
|
||||
}
|
||||
|
||||
void SMIterator::next(){
|
||||
//Complexity: O(1)
|
||||
if (this->current == nullptr)
|
||||
throw exception();
|
||||
this->current = this->current->next;
|
||||
}
|
||||
|
||||
bool SMIterator::valid() const{
|
||||
//Complexity: O(1)
|
||||
if(this->current == nullptr)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
TElem SMIterator::getCurrent() const{
|
||||
//Complexity: O(1)
|
||||
if(this->current==nullptr)
|
||||
throw exception();
|
||||
return this->current->element;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user