this code shows in reverse order the contents of the list linked from node n with the help of a stack. One question, if instead of showing the content of the list in reverse order, I want to show it in normal order, how should I handle the stack to show it that way?
This is the code that shows the data in reverse order, I want to know what I have to modify to show in normal order, from the first position to the last one. Help is appreciated.
template <class T>
ostream& dll_t<T>::write_reverse2(dll_node_t<T>* n, ostream& os) const {
stack_v_t<dll_node_t<T>*> stack;
while (n != NULL) {
stack.push_back(n);
n = n->get_next();
}
while(!stack.empty()){
stack.top()->write(os);
stack.pop();
}
return os;
}
template <class T>
ostream& dll_t<T>::write_reverse2(ostream& os) const {
reverse2(head_, os);
return os;
}
template <class T>
class stack_v_t{
private:
vector_t<T> v_;
int top_;
public:
stack_v_t(int max_sz);
~stack_v_t(void);
bool empty(void);
T top(void);
void pop(void);
void push(T dato);
};