So I have a custom linked list. Every node is a struct which has a next pointer to a the next node and the last->next is null.
struct nodo {
T value;
nodo *next;
nodo() : next(0) {}
nodo(const T &v, nodo *n=0): value(v), next(n){}
};
I want to implement iterators in my class and since my class supports random access with operator[] then I chose to implement Random Access Iterators. Now, my problem is on the following operator:
difference_type operator-(const iterator &other) {
}
It returns the number of elements between this iterator and other iterator, but I'm not sure what's the best to implement it.
iterator, can be used from any position to get to any other. If that was truly the case, calculating the difference shouldn't be too difficult. You can easily implement a forward iterator. Why isn't that good enough? - StoryTeller - Unslander Monica