I have to make a project for college. I have to implement a doubly linked list on an array in C++. The thing is that I'm not allowed to use STL/templates. I implemented the DLL and I'll leave here a code sample:
class DLLA {
private:
int* elements;
int* next;
int* prev;
int size;
int capacity;
// some other variables here if needed
public:
DLLA();
~DLAA();
int getSize();
void addFirst(int x);
void addLast(int x);
void addAtPosition(int x, int position);
// and some other operations and functions
private:
void resize();
};
The problem is that I have to also implement an iterator and I don't really know how. I tried with nested classes but I don't know how to access the DLLA's data members from the iterator and how to generally implement it. Something like this...
class DLLA {
public:
// data members
private:
// functions
public:
class iterator {
private:
int current; // the current position in the vector
public:
void next();
void prev();
// and some other functions
};
};
And also, having nested classes, is it possible to have a function getIterator() in the interface of DLLA which returns the iterator for DLLA?