Good, I have an exercise in which I'm stuck, this is the statement:
Implement the RECURSIVE method (DO NOT CONFUSE PLEASE WITH ANOTHER EXERCISE THAT YOU PUT WHERE YOU SAY NO RESOURCE, THIS IS RECURSIVE) of the class
dll_t ostream& dll_t<T>::write_reverse(dll_node_t<T>* n, ostream& os) const
that shows in reverse order the content of the linked list invoked from the node n . Only thedll_node_t* get_next()
method of the classdll_node_t
can be used to access the next element. In no case will the methoddll_node_t* get_prev()
be allowed.
THIS ARE THE CLASSES THAT GIVE ME:
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);
};
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 it this way, I know that my approach is wrong, that I have gaps in some aspects, but I appreciate any help:
template<class T>
ostream& dll_t<T>:: write_reverse(dll_node_t<T>* n, ostream& os) const {
assert(!empty());
while(n!=NULL){
n=n->get_data();
n.write(os);
}
I stayed there, I appreciate any help.
Thanks.