Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- };
- template <class T>
- class stack_v_t{
- private:
- vector_t<T> v_;
- int top_;
- public:
- stack_v_t(int max_sz);//Constructor
- //Necesitaria n constructor:stack_v_t();
- ~stack_v_t(void);
- bool empty(void);
- T top(void);
- void pop(void);
- void push(T dato);
- };
- 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;
- /*stack no es un puntero es un stack del tipo
- stack_v_t<dll_node_t<T>*>
- al inicializarse asi la clase stack_v_t debe tener un
- constructor sin parametros y las llamadas a los metodos se
- hacen con '.' en lugar de ->
- */
- while (n != NULL) {
- stack.push_back(n);
- n = n->get_next();
- }
- while(!stack.empty()){
- stack.top()->write(os);//stack.top() devuelve un objeto
- // tipo T como se garantiza que tenga el metodo ->write(os)???
- //Puede ser?: os<<stack.top();
- stack.pop();
- }
- return os;
- }
- template <class T>
- ostream& dll_t<T>::write_reverse2(ostream& os) const {
- reverse2(head_, os);
- return os;
- }
- const int STACK_CAPACITY= 100;//maxima capacidad de la pila
- 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(STACK_CAPACITY);
- while (n != NULL) {
- stack.push_back(n);
- n = n->get_next();
- }
- while(!stack.empty()){
- stack.write(stack.top());//Cambie aqui usando el metodo write de la clase stack_v_t
- stack.pop();
- }
- return os;
- }
- template <class T>
- ostream& dll_t<T>::write_reverse2(ostream& os) const {
- reverse2(head_, os);
- return os;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement