School Commit Init
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include "Map.h"
|
||||
#include "MapIterator.h"
|
||||
#include <exception>
|
||||
using namespace std;
|
||||
|
||||
|
||||
MapIterator::MapIterator(const Map& d) : map(d)
|
||||
{
|
||||
//O(1)
|
||||
this->_current=0;
|
||||
while (this->_current<this->map._capacity && this->map._elements[this->_current]==NULL_TELEM)
|
||||
{
|
||||
this->_current++;
|
||||
}
|
||||
this->_first=this->_current;
|
||||
}
|
||||
|
||||
|
||||
void MapIterator::first() {
|
||||
//O(1)
|
||||
this->_current=this->_first;
|
||||
}
|
||||
|
||||
|
||||
void MapIterator::next() {
|
||||
//O(1)
|
||||
if(this->valid()){
|
||||
this->_current++;
|
||||
while (this->_current<this->map._capacity && this->map._elements[this->_current]==NULL_TELEM)
|
||||
{
|
||||
this->_current++;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw exception();
|
||||
}
|
||||
|
||||
|
||||
TElem MapIterator::getCurrent(){
|
||||
//O(1)
|
||||
if(this->valid())
|
||||
return this->map._elements[this->_current];
|
||||
throw exception();
|
||||
}
|
||||
|
||||
|
||||
bool MapIterator::valid() const {
|
||||
//O(1)
|
||||
if(this->_current<this->map._capacity && this->map._elements[this->_current]!=NULL_TELEM)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user