#include "ListIterator.h"
#include "SortedIndexedList.h"
#include <iostream>

using namespace std;

ListIterator::ListIterator(const SortedIndexedList& list) : list(list) {
	// O(1)
	this->_current = list._head;
}

void ListIterator::first(){
	// O(1)
	this->_current = this->list._head;
}

void ListIterator::next(){
	// O(1)
	if(!this->valid())
		throw exception();
	this->_current = this->list._next[this->_current];
}

bool ListIterator::valid() const{
	// O(1)
	if(this->_current != -1)
		return true;
	return false;
}

TComp ListIterator::getCurrent() const{
	// O(1)
	if(this->valid())
		return this->list._elements[this->_current];
	return NULL_TCOMP;
}


void ListIterator::previous(){
	// O(1)
	if(!this->valid())
		throw exception();
	this->_current = this->list._prev[this->_current];
}

void ListIterator::last(){
	// O(1)
	this->_current = this->list._tail;
}