Guest User

Untitled

a guest
May 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #ifndef TablaH
  2. #define TablaH
  3.  
  4. template <class T>
  5. class Tabla
  6. {
  7. private:
  8. int numElem;
  9. T* tabla;
  10. public:
  11. Tabla();
  12. ~Tabla();
  13. int dameNumElem() const;
  14. bool buscaPos(const T&, int&);
  15. void push(const T&);
  16. bool pop(T&);
  17. bool dameElem(int, T&) const;
  18. } ;
  19.  
  20. //----------------------------------------------------------------------------
  21. #endif
  22.  
  23. ------------------------------------------------------------------------------
  24. ------------------------------------------------------------------------------
  25. ------------------------------------------------------------------------------
  26. ------------------------------------------------------------------------------
  27. ------------------------------------------------------------------------------
  28.  
  29. #include <vcl.h>
  30. #pragma hdrstop
  31.  
  32. #include "Tabla.h"
  33.  
  34. //----------------------------------------------------------------------------
  35.  
  36. #pragma package(smart_init)
  37.  
  38.  
  39. template <class T>
  40. Tabla<T>::Tabla()
  41. {
  42. numElem = 0;
  43. tabla = new T[MAX_TABLA];
  44. }
  45.  
  46. template <class T>
  47. Tabla<T>::~Tabla()
  48. {
  49. numElem = 0;
  50. delete[MAX_TABLA] tabla;
  51. tabla = NULL;
  52. }
  53.  
  54. template <class T>
  55. int Tabla<T>::dameNumElem() const
  56. {
  57. return numElem;
  58. }
  59.  
  60. template <class T>
  61. bool Tabla<T>::buscaPos(const T& e, int& i)
  62. {
  63. for (int j=0;j<=numElem;j++)
  64. {
  65. if (e == tabla[j])
  66. {
  67. i = j;
  68. return true;
  69. }
  70. else
  71. {
  72. i = numElem;
  73. return false;
  74. }
  75. }
  76. }
  77.  
  78. template <class T>
  79. void Tabla<T>::push(const T& d)
  80. {
  81. int i=0;
  82.  
  83. while (i<=numElem) do
  84. {
  85. if (tabla[i]==NULL)
  86. {
  87. tabla[i]=d;
  88. numElem++;
  89. return;
  90. }
  91. else
  92. i++;
  93. }
  94.  
  95. if (i>numElem)
  96. {
  97. int MAX_TABLA2 = MAX_TABLA*2;
  98. T* tabla2 = new T[MAX_TABLA2];
  99. for (int j=0;j<=MAX_TABLA;j++)
  100. {
  101. tabla2[j]=tabla1[j];
  102. }
  103. tabla2[MAX_TABLA+1]=d;
  104. numElem++;
  105. MAX_TABLA = MAX_TABLA2;
  106. tabla = tabla2;
  107. delete tabla2;
  108. tabla2 = NULL;
  109. }
  110. }
  111.  
  112. template <class T>
  113. bool Tabla<T>::pop(T& d)
  114. {
  115. int i=0;
  116.  
  117. while (i<numElem) do
  118. {
  119. if (tabla[i]==NULL)
  120. {
  121. //elimina el elemento de la posicion i-1
  122. //porque seria el ultimo y poner un return true
  123. //para que se salga del metodo
  124. }
  125. else
  126. i++;
  127. }
  128.  
  129. if (i==numElem)
  130. {
  131. //elimina el elemento en la posicion numElem y return true
  132. }
  133. }
  134.  
  135. template <class T>
  136. bool Tabla<T>::dameElem(int i, T& v) const
  137. {
  138. if ((i<0)||(i>numElem))
  139. return false;
  140. else
  141. {
  142. v = tabla[i];
  143. return true;
  144. }
  145. }
Add Comment
Please, Sign In to add comment