Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. template <class T>
  2. ostream& dll_t<T>::write_reverse2(dll_node_t<T>* n, ostream& os) const {
  3.  
  4. stack_v_t<dll_node_t<T>*> stack;
  5.  
  6. while (n != NULL) {
  7. stack.push_back(n);
  8. n = n->get_next();
  9. }
  10.  
  11. while(!stack.empty()){
  12.  
  13. stack.top()->write(os);
  14. stack.pop();
  15. }
  16.  
  17. return os;
  18. }
  19.  
  20. template <class T>
  21. ostream& dll_t<T>::write_reverse2(ostream& os) const {
  22.  
  23. reverse2(head_, os);
  24.  
  25. return os;
  26. }
  27.  
  28. template <class T>
  29. class stack_v_t{
  30. private:
  31. vector_t<T> v_;
  32. int top_;
  33. public:
  34. stack_v_t(int max_sz);
  35. ~stack_v_t(void);
  36. bool empty(void);
  37. T top(void);
  38. void pop(void);
  39. void push(T dato);
  40. };
  41.  
  42. template <class T>
  43. class stack_v_t{
  44. private:
  45. vector_t<T> v_;
  46. int top_;
  47. public:
  48. stack_v_t(int max_sz);//Constructor
  49. //Necesitaria n constructor:stack_v_t();
  50. ~stack_v_t(void);
  51. bool empty(void);
  52. T top(void);
  53. void pop(void);
  54. void push(T dato);
  55. };
  56.  
  57. template <class T>
  58. ostream& dll_t<T>::write_reverse2(dll_node_t<T>* n, ostream& os) const {
  59.  
  60. stack_v_t<dll_node_t<T>*> stack;
  61. /*stack no es un puntero es un stack del tipo
  62. stack_v_t<dll_node_t<T>*>
  63. al inicializarse asi la clase stack_v_t debe tener un
  64. constructor sin parametros y las llamadas a los metodos se
  65. hacen con '.' en lugar de ->
  66. */
  67.  
  68. while (n != NULL) {
  69. stack.push_back(n);
  70. n = n->get_next();
  71. }
  72.  
  73. while(!stack.empty()){
  74.  
  75. stack.top()->write(os);//stack.top() devuelve un objeto
  76. // tipo T como se garantiza que tenga el metodo ->write(os)???
  77. //Puede ser?: os<<stack.top();
  78. stack.pop();
  79. }
  80.  
  81. return os;
  82. }
  83.  
  84. template <class T>
  85. ostream& dll_t<T>::write_reverse2(ostream& os) const {
  86.  
  87. reverse2(head_, os);
  88.  
  89. return os;
  90. }
  91.  
  92. const int STACK_CAPACITY= 100;//maxima capacidad de la pila
  93. template <class T>
  94. ostream& dll_t<T>::write_reverse2(dll_node_t<T>* n, ostream& os) const {
  95.  
  96. stack_v_t<dll_node_t<T>*> stack(STACK_CAPACITY);
  97.  
  98. while (n != NULL) {
  99. stack.push_back(n);
  100. n = n->get_next();
  101. }
  102.  
  103. while(!stack.empty()){
  104.  
  105. stack.write(stack.top());//Cambie aqui usando el metodo write de la clase stack_v_t
  106. stack.pop();
  107. }
  108.  
  109. return os;
  110. }
  111.  
  112. template <class T>
  113. ostream& dll_t<T>::write_reverse2(ostream& os) const {
  114.  
  115. reverse2(head_, os);
  116.  
  117. return os;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement