I have a battery exercise, it says:
Implement the dll_t void class method select (dll_t * > & L, const T & x), which saves
within the list L the pointers to nodes of the invoking list that has as content x.
also, they give me the following classes:
template <class T>
class dll_t {
private:
dll_node_t<T>* head_;
dll_node_t<T>* tail_;
int sz_;
public:
dll_t(void);
~dll_t(void);
void insert_tail(dll_node_t<T>*);
void insert_head(dll_node_t<T>*);
dll_node_t<T>* extract_tail(void);
dll_node_t<T>* extract_head(void);
dll_node_t<T>* get_tail(void) const;
dll_node_t<T>* get_head(void) const;
bool empty(void);
void remove(dll_node_t<T>*);
ostream& write(ostream& os) const;
void select(dll_t<dll_node_t<T>*>& L, const T& x);
private:
bool igual(const T& a, const T&b);
};
and this one:
template <class T>
class dll_node_t {
private:
dll_node_t<T>* next_;
dll_node_t<T>* prev_;
T data_;
public:
dll_node_t();
dll_node_t(const T& data);
virtual ~dll_node_t(void);
void set_next(dll_node_t<T>*);
void set_prev(dll_node_t<T>*);
dll_node_t<T>* get_next(void) const;
dll_node_t<T>* get_prev(void) const;
void set_data(const T& data);
T get_data(void) const;
ostream& write(ostream& os) const;
};
I tried to do so, before compiling it I knew I had some basic error in the approach:
template<class T>
void vector_t :: select (dll_t<dll_node_t<T>*>& L, const T& x){
dll_t<T> lista;
dll_node_t<T>* aux = lista.get_head();
while(aux!=NULL){
T dato = aux->get_data();
if ( dato == x){
aux = new dll_node_t<T> (T(dato));
L.insert_tail(aux);
}
aux= aux -> get_next();
}
I do not know where I have this error in the approach to the exercise, I'm still looking for it.
Thanks